#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";
}

#include<bits/stdc++.h>
#define maxn 200005
#define LL long long
using namespace std;
const int mod = 1e9+7;
int n,Q,pre,now;
struct Seg{
	LL mn[maxn<<2],tag[maxn<<2]; int flg;
	Seg(){memset(mn,0x3f,sizeof mn);}
	inline void add(int i,LL v){mn[i]+=v,tag[i]+=v;}
	inline void down(int i){if(tag[i]) add(i<<1,tag[i]),add(i<<1|1,tag[i]),tag[i]=0;}
	void ins(int i,int l,int r,int x,LL v){
		if(l==r) {mn[i]=min(mn[i],v+l*flg);return;}
		int mid=(l+r)>>1; down(i);
		x<=mid?ins(i<<1,l,mid,x,v):ins(i<<1|1,mid+1,r,x,v);
		mn[i]=min(mn[i<<1],mn[i<<1|1]);
	}
	LL qry(int i,int l,int r,int x,int y){
		if(x<=l&&r<=y) return mn[i];
		int mid=(l+r)>>1; LL ret=mn[0]; down(i);
		if(x<=mid) ret=min(ret,qry(i<<1,l,mid,x,y));
		if(y>mid) ret=min(ret,qry(i<<1|1,mid+1,r,x,y));
		return ret;
	}
	LL whole(int i,int l,int r){
		if(l==r) return mn[i]+l;
		int mid=(l+r)>>1; down(i);
		return min(whole(i<<1,l,mid),whole(i<<1|1,mid+1,r));
	}
}T1,T2;
int main()
{
	scanf("%d%d%d%d",&n,&Q,&pre,&now),T1.flg=-1,T2.flg=1;
	T1.ins(1,1,n,now,0),T2.ins(1,1,n,now,0);
	for(int i=1;i<=Q;i++,pre=now){
		scanf("%d",&now); if(now==pre) continue;
		LL tmp=min(T1.qry(1,1,n,1,now)+now,T2.qry(1,1,n,now,n)-now);
		T1.add(1,abs(now-pre)),T2.add(1,abs(now-pre));
		T1.ins(1,1,n,pre,tmp),T2.ins(1,1,n,pre,tmp);
	}
	printf("%lld\n",T1.whole(1,1,n));
}