#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
const int inf = 1e15;
int mod = 1e9+7;

//最小値取得
class SegmentTree{
public:
	int n = 1;
	vector<int> seg[2];
	//m要素のセグメントツリー作成
	void init(int m){
		while(n < m)n *= 2;
		rep(i,2)seg[i].resize(2*n);
		rep(i,2)fill(all(seg[i]), inf);
	}
	//kの値をxに変更
	void update(int t, int k, int x){
		k += n-1;
		seg[t][k] = x;
		while(k > 0){
			k = (k-1)/2;
			seg[t][k] = min(seg[t][k*2+1], seg[t][k*2+2]);
		}
	}
	int calc(int t, int a, int b, int k, int l, int r){
		if(b <= l || r <= a)return inf;
		if(a <= l && r <= b)return seg[t][k];
		int vl = calc(t, a, b, k*2+1, l, (l+r)/2);
		int vr = calc(t, a, b, k*2+2, (l+r)/2, r);
		return min(vl, vr);
	}
	//[a,b)の最小値を求める
	int get(int t, int a, int b){return calc(t, a, b, 0, 0, n);}
};

int a[200004], dp[2][200004];
int n, q, x, y;
SegmentTree seg;
int solve(){
	int ans = inf, mem = 0;
	rrep(i,q){
		int vl = seg.get(0, 0, a[i])+a[i];
		int vr = seg.get(1, a[i], n)-a[i];
		int res = min(vl, vr)-llabs(a[i]-a[i-1]);
		seg.update(0, a[i-1], res-a[i-1]);
		seg.update(1, a[i-1], res+a[i-1]);
		mem += llabs(a[i]-a[i-1]);
	}
	rep(i,n)chmin(ans, seg.get(0, i, i+1)+i);
	return ans+mem;
}

signed main(){
	scanf("%lld%lld%lld%lld", &n, &q, &x, &y);
	rrep(i,q)scanf("%lld", &a[i]), a[i]--;
	x--;y--;
	
	int ans = inf;
	a[0] = y;
	seg.init(n+1);
	seg.update(0, x, -x);
	seg.update(1, x, x);
	chmin(ans, solve());
	
	a[0] = x;
	seg.init(n+1);
	seg.update(0, y, -y);
	seg.update(1, y, y);
	chmin(ans, solve());
	
	printf("%lld\n", ans);
	return 0;
}
