// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef unsigned long long ull;

#define int long long

int hmt() {int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';if(n) x=-x;return x;}

#define in hmt()

#define ins ({string x;char c=getchar();for(;c==' '||c=='\n';c=getchar());for(;c!=' '&&c!='\n';c=getchar()) x+=c;x;})

#define forinc(i,a,b) for(int i=a,_b=b;i<=_b;++i)

#define fordec(i,a,b) for(int i=a;i>=b;--i)

#define forb(i,BS) for(int i=BS._Find_first();i< BS.size();i = BS._Find_next(i))

#define forv(a,b) for(auto &a:b)

#define pb push_back

#define pii pair<int,int>

#define fi first

#define se second

#define all(a) a.begin(),a.end()

#define reset(f,x) memset(f,x,sizeof(f))

#define bit(x,i) ((x>>(i-1))&1)

#define onbit(x,i) (x|(1<<(i-1)))

#define offbit(x,i) (x&~(1<<(i-1)))

const int N=200010;

int n,Q,A,B,a[N],oo,s[N],f[N],ans;

struct bit

{

	int t[N];

	void rs()

	{

	    reset(t,127);oo=t[0];

	}

	void upd(int i,int x)

	{

		for(;i<=n;i+=i&-i) t[i]=min(t[i],x);

	}

	int get(int i)

	{

		int g=oo;

		for(;i;i-=i&-i) g=min(g,t[i]);

		return g;

	}

}T[2];

void add(int i,int x)

{

	T[0].upd(i,x-i);

	T[1].upd(n-i+1,i+x);

}

main()

{

    //freopen("C.inp","r",stdin);

	n=in,Q=in,A=in,B=in;

	forinc(i,1,Q) a[i]=in;

	forinc(i,2,Q) s[i]=s[i-1]+abs(a[i]-a[i-1]);

	T[0].rs();T[1].rs();

	add(B,abs(A-a[1]));

	add(A,abs(B-a[1]));

	ans=s[Q]+min(abs(A-a[1]),abs(B-a[1]));

	forinc(i,2,Q)

	{

		f[i]=min(T[0].get(a[i])+a[i],T[1].get(n-a[i]+1)-a[i])+s[i-1];

		add(a[i-1],f[i]-s[i]);

		ans=min(ans,f[i]+s[Q]-s[i]);

	}

	cout<<ans<<"\n";

}


// Faster C++ solution for the same problem (measured speedup: 4.144483125577935x):
#include <bits/stdc++.h>



using namespace std;



#define int long long



int n,q,a,b;

int x[200001], f[200001];



struct Node

{

	int val_1, val_2, lazy; // val_1 : f[i] - i, val_2 : f[i] + i

	Node(){}

}Tree[800001];



void build(int node,int l,int r)

{    	

	if (l == r)

	{

		Tree[node].val_1 = f[l] - l;

		Tree[node].val_2 = f[l] + l;

		return;

	}

	int mi = (l + r)/2;

	build(node*2,l,mi);

	build(node*2 + 1,mi + 1,r);

	Tree[node].val_1 = min(Tree[node*2].val_1,Tree[node*2 + 1].val_1);

	Tree[node].val_2 = min(Tree[node*2].val_2,Tree[node*2 + 1].val_2);

}



void diffuse(int node,int l,int r)

{

	if (Tree[node].lazy)

	{

		Tree[node].val_1 += Tree[node].lazy;

		Tree[node].val_2 += Tree[node].lazy;

		if (l != r)

		{

			Tree[node*2].lazy += Tree[node].lazy;

			Tree[node*2 + 1].lazy += Tree[node].lazy;

		}

		Tree[node].lazy = 0;

	}

}



void update(int node,int l,int r,int ll,int rr,int val)

{

	diffuse(node,l,r);

	if (r  < ll || rr < l) 

		return;

	if (ll <= l && r <= rr)

	{

		Tree[node].lazy += val;

		diffuse(node,l,r);

		return;

	}

	int mi = (l + r)/2;

	update(node*2,l,mi,ll,rr,val);

	update(node*2 + 1,mi + 1,r,ll,rr,val);

	Tree[node].val_1 = min(Tree[node*2].val_1,Tree[node*2 + 1].val_1);

	Tree[node].val_2 = min(Tree[node*2].val_2,Tree[node*2 + 1].val_2);

}



int query(int node,int l,int r,int ll,int rr,int type)

{

	diffuse(node,l,r);

	if (r < ll || rr < l)

		return 1e18;

	if (ll <= l && r <= rr)

	{

		if (type == 1) return Tree[node].val_1;

		else return Tree[node].val_2;

	}			

	int mi = (l + r)/2;

	int a = query(node*2,l,mi,ll,rr,type);

	int b = query(node*2 + 1,mi + 1,r,ll,rr,type);

	return min(a,b);

}



int res = 1e18;



void cal_ans(int node,int l,int r)

{

	diffuse(node,l,r);

	if (l == r)

	{

		res = min(res,Tree[node].val_1 + l);

		return;

	}

	int mi = (l + r)/2;

	cal_ans(node*2,l,mi);

	cal_ans(node*2 + 1,mi + 1,r);

}



int32_t main()

{

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);



	cin >> n >> q >> a >> b;

	for (int i=1;i<=q;i++)

		cin >> x[i];

	for (int i=1;i<=n;i++)

	{

		f[i] = min(abs(a - x[1]) + abs(b - i), abs(a - i) + abs(b - x[1]));

		//cerr << f[i] << ' ';

	}

	//cerr << '\n';	

	build(1,1,n);

	for (int i=2;i<=q;i++)

	{

		int val_l = query(1,1,n,1,x[i],1) + x[i];

		int val_r = query(1,1,n,x[i],n,2) - x[i];

		update(1,1,n,1,n,abs(x[i] - x[i-1]));	

		int cur_val = query(1,1,n,x[i-1],x[i-1],1) + x[i-1];

		//cerr << '?' << cur_val << ' ' << val_l << ' ' << val_r << '\n';

		update(1,1,n,x[i-1],x[i-1],min(0LL, -(cur_val - min(val_l, val_r))));

		//for (int j=1;j<=n;j++)

		//	cerr << query(1,1,n,j,j,1) + j << ' ';

		//cerr << '\n';	

	}

	cal_ans(1,1,n);

	cout << res;

}