// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define N 200100

#define Inf 100000000000LL

#define ll long long

struct node{

	ll x,y;

	node(){}

	node(ll x,ll y):x(x),y(y){};

}s1[N<<2],s2[N<<2];

ll tag[N<<2],x[N];

void down(ll t){

	if (tag[t]!=0){

		s1[t<<1].y+=tag[t];

		s2[t<<1].y+=tag[t];

		s1[t<<1|1].y+=tag[t];

		s2[t<<1|1].y+=tag[t];

		tag[t<<1]+=tag[t];

		tag[t<<1|1]+=tag[t];

		tag[t]=0;

	}

}

void update(ll t){

	if (s1[t<<1].y-s1[t<<1].x<s1[t<<1|1].y-s1[t<<1|1].x) s1[t]=s1[t<<1]; else s1[t]=s1[t<<1|1];

	if (s2[t<<1].y+s2[t<<1].x<s2[t<<1|1].y+s2[t<<1|1].x) s2[t]=s2[t<<1]; else s2[t]=s2[t<<1|1];

}

void build(ll k,ll l,ll r){

	if (l==r){s1[k]=s2[k]=node(l,Inf); return;}

	ll mid=l+r>>1;

	build(k<<1,l,mid);

	build(k<<1|1,mid+1,r);

	update(k);

}

void add(ll t,ll l,ll r,ll L,ll R,ll k){

	if (L<=l && r<=R){

		s1[t].y+=k;	s2[t].y+=k;	tag[t]+=k;

		return;

	}

	down(t);

	ll mid=l+r>>1;

	if (L<=mid) add(t<<1,l,mid,L,R,k);

	if (R>mid) add(t<<1|1,mid+1,r,L,R,k);

	update(t);

}

ll get1(ll t,ll l,ll r,ll L,ll R){

	if (L<=l && r<=R){return s1[t].y-s1[t].x;}

	down(t);

	ll mid=l+r>>1,ans=Inf*10;

	if (L<=mid) ans=min(ans,get1(t<<1,l,mid,L,R));

	if (R>mid) ans=min(ans,get1(t<<1|1,mid+1,r,L,R));

	return ans;

}

ll get2(ll t,ll l,ll r,ll L,ll R){

	if (L<=l && r<=R)return s2[t].y+s2[t].x;

	down(t);

	ll mid=l+r>>1,ans=Inf*10;

	if (L<=mid) ans=min(ans,get2(t<<1,l,mid,L,R));

	if (R>mid) ans=min(ans,get2(t<<1|1,mid+1,r,L,R));

	return ans;

}

ll get(ll t,ll l,ll r){

	if (l==r){return s1[t].y;}

	down(t);

	ll mid=l+r>>1;

	return min(get(t<<1,l,mid),get(t<<1|1,mid+1,r));

}



int main(){

	ll n,a,b,Q;

	scanf("%lld%lld%lld%lld",&n,&Q,&a,&b);

	x[0]=a;

	for (ll i=1;i<=Q;i++)

		scanf("%lld",&x[i]);

	build(1,1,n);

	add(1,1,n,b,b,-Inf);

	get(1,1,n);

	for (ll i=1;i<=Q;i++){

		ll t1=get1(1,1,n,1,x[i])+x[i],t2=get2(1,1,n,x[i],n)-x[i];

		ll tmp=min(t1,t2);

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

		ll t3=get1(1,1,n,x[i-1],x[i-1])+x[i-1];

		if (tmp<t3) add(1,1,n,x[i-1],x[i-1],tmp-t3);

	}

	printf("%lld\n",get(1,1,n));

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

#define MN 200005

using namespace std;

typedef long long ll;

int n,q;

ll mk[MN<<2];

struct node{

	ll mi[4];

	friend node operator+(node x,node y){

		node z;

		for(int i=1;i<=3;i++)z.mi[i]=min(x.mi[i],y.mi[i]);

		return z;

	}

}T[MN<<2];

void uadd(int v){for(int i=1;i<=3;i++)T[1].mi[i]+=v;mk[1]+=v;}

void pushdown(int k,int l,int r){

	mk[k<<1]+=mk[k],mk[k<<1|1]+=mk[k];

	for(int i=1;i<=3;i++)T[k<<1].mi[i]+=mk[k],T[k<<1|1].mi[i]+=mk[k];mk[k]=0;

}

void update(int l,int r,int a,int k,ll ad){

	if(l==r)return (void)(T[k].mi[1]>ad?(T[k].mi[1]=ad,T[k].mi[2]=ad-l,T[k].mi[3]=ad+l):0);if(mk[k])pushdown(k,l,r);int mid=(l+r)>>1;

	if(a<=mid)update(l,mid,a,k<<1,ad);else update(mid+1,r,a,k<<1|1,ad);T[k]=T[k<<1]+T[k<<1|1];

}

ll que1(int l,int r,int a,int b,int k){

	if(l==a&&r==b)return T[k].mi[2];if(mk[k])pushdown(k,l,r);int mid=(l+r)>>1;

	if(b<=mid)return que1(l,mid,a,b,k<<1);if(a>mid)return que1(mid+1,r,a,b,k<<1|1);

	return min(que1(l,mid,a,mid,k<<1),que1(mid+1,r,mid+1,b,k<<1|1));

}

ll que2(int l,int r,int a,int b,int k){

	if(l==a&&r==b)return T[k].mi[3];if(mk[k])pushdown(k,l,r);int mid=(l+r)>>1;

	if(b<=mid)return que2(l,mid,a,b,k<<1);if(a>mid)return que2(mid+1,r,a,b,k<<1|1);

	return min(que2(l,mid,a,mid,k<<1),que2(mid+1,r,mid+1,b,k<<1|1));

}

void build(int l,int r,int k){

	if(l==r)return (void)(T[k].mi[1]=T[k].mi[2]=T[k].mi[3]=1e18);int mid=(l+r)>>1;

	build(l,mid,k<<1);build(mid+1,r,k<<1|1);T[k]=T[k<<1]+T[k<<1|1];

}

int main(){

	int a,b;scanf("%d%d%d%d",&n,&q,&a,&b);build(1,n,1);

	update(1,n,b,1,0);

	int lst=a,x;

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

		scanf("%d",&x);

		ll tmp=min(que1(1,n,1,x,1)+x,que2(1,n,x,n,1)-x);

		uadd(abs(x-lst));update(1,n,lst,1,tmp);lst=x;

	}printf("%lld\n",T[1].mi[1]);

}

// Fastest known solution for this problem: