#include <bits/stdc++.h>
#define rep(i, j, k) for(int i = j; i <= k; ++i)
#define dep(i, j, k) for(int i = j; i >= k; --i)
#define enter putchar('\n')
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)

typedef long long ll;

using namespace std;

const int maxn = 3e5 + 5;
const int LOG = 35;
const int inf = 0x3f3f3f3f;

int n, m, a[maxn];

inline int read() {
	char ch = getchar(); int u = 0, f = 1;
	while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar(); }
	while(isdigit(ch))  { u = u * 10 + ch - 48; ch = getchar(); } return u * f;
}

struct SEG {
	#define ls p << 1
	#define rs p << 1 | 1
	#define mid (l + r >> 1)
	struct Node {
		ll mn, tag;
		Node() { tag = 0; mn = (1ll << 60); }
	} t[maxn << 2];

	inline void pushtag(int p, ll x) {
		t[p].tag += x; t[p].mn += x;
	}

	inline void pushdown(int p) {
		if(t[p].tag) {
			pushtag(ls, t[p].tag);
			pushtag(rs, t[p].tag);
			t[p].tag = 0;
		}
	}

	inline void modify(int l, int r, int pos, int p, ll x) {
		if(l == r) { t[p].mn = min(t[p].mn, x); return; }
		pushdown(p);
		if(pos <= mid) modify(l, mid, pos, ls, x);
		else modify(mid + 1, r, pos, rs, x);
		t[p].mn = min(t[ls].mn, t[rs].mn);
	}

	inline void add(int l, int r, int ql, int qr, int p, ll x) {
		if(l == ql && r == qr) return pushtag(p, x);
		pushdown(p);
		if(qr <= mid) add(l, mid, ql, qr, ls, x);
		else if(ql > mid) add(mid + 1, r, ql, qr, rs, x);
		else add(l, mid, ql, mid, ls, x), add(mid + 1, r, mid + 1, qr, rs, x);
		t[p].mn = min(t[ls].mn, t[rs].mn);
	}
	
	inline ll query(int l, int r, int ql, int qr, int p) {
//		cerr << l << " " << r << " " << ql << " " << qr << endl;
		if(l == ql && r == qr) return t[p].mn;
		pushdown(p);
		if(qr <= mid) return query(l, mid, ql, qr, ls);
		else if(ql > mid) return query(mid + 1, r, ql, qr, rs);
		else return min(query(l, mid, ql, mid, ls), query(mid + 1, r, mid + 1, qr, rs));
	}
	
	inline ll getmin(int l, int r, int p, int ty) {
		if(l == r) return t[p].mn + ty * r;
		pushdown(p);
		return min(getmin(l, mid, ls, ty), getmin(mid + 1, r, rs, ty));
	}
	#undef ls
	#undef rs
	#undef mid
} T, RT;


int main() {
	n = read(); m = read(); a[1] = read(); a[2] = read(); 
	rep(i, 1, m) a[i + 2] = read();
	T.modify(1, n, a[1], 1, a[1]); RT.modify(1, n, a[1], 1, -a[1]);
	rep(i, 3, m + 2) {
		ll tmp = min(T.query(1, n, a[i], n, 1) - a[i], RT.query(1, n, 1, a[i], 1) + a[i]);
//		cerr << tmp << endl;
		T.add(1, n, 1, n, 1, abs(a[i] - a[i - 1]));
		RT.add(1, n, 1, n, 1, abs(a[i] - a[i - 1]));
		T.modify(1, n, a[i - 1], 1, tmp + a[i - 1]); RT.modify(1, n, a[i - 1], 1, tmp - a[i - 1]);
	}
	cout << T.getmin(1, n, 1, -1) << endl;
	return 0;
}
/*
f[2][1] = 0
f[3][1] = 5 -> ABB
f[3][2] = 2 -> ABA
f[4][1] = 7 -> ABBB
f[4][2] = 4 -> ABAA
f[4][3] = 5 -> ABAB
*/
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

#define N 262144
ll dp[2][2*N+5];
int n,q,a,b;

#define INM 100000000000000000LL
//0-index
void update(int id,int k,ll a)
{
	k += N-1;
	dp[id][k] = a;
	while(k > 0)
	{
		k = (k-1)/2;
		dp[id][k] = min(dp[id][k*2+1],dp[id][k*2+2]);
	}
}


ll query(int id,int a,int b,int k=0,ll l=0,ll r=N)
{
	if(r <= a || b <= l)return INM;
	if(a <= l && r <= b)return dp[id][k];
	else
	{
		ll vr = query(id,a,b,k*2+1,l,(l+r)/2);
		ll vl = query(id,a,b,k*2+2,(l+r)/2,r);
		return min(vr,vl);
	}
}

int main()
{
	cin >> n >> q >> a >> b;
	REP(i,2)REP(j,N)update(i,j,INM);
	
	vector<int> que;que.PB(a);
	
	REP(i,q)
	{
		int tmp;cin >> tmp;que.PB(tmp);
	}
	
	update(0,b,b);
	update(1,b,n-b);
	
	//cout  << query(1,0,n+1) << endl;
	
	ll sum = 0;
	for(int i = 1;i <= q;i++)
	{
		ll tmp = abs(que[i-1]-que[i]);
		sum += tmp;
		
		ll mi = min(query(1,0,que[i]+1)-(n-que[i]),query(0,que[i],n+1)-que[i]);
		//cout << query(1,0,que[i]+1)-que[i]+1<< ' ' << query(0,que[i],n+1)-que[i] << endl;
		update(0,que[i-1],mi-tmp+que[i-1]);
		update(1,que[i-1],mi-tmp+n-que[i-1]);
	}
	

	
	ll ans = INM;
	
	REP(i,n+1)
	{
		ans = min(ans,dp[0][i+N-1]-i);
		ans = min(ans,dp[1][i+N-1]-(n-i));
	}
	
	cout << ans + sum << endl;

	return 0;
}