#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(a) for(int k=head[a];k;k=e[k].ne)
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=1e6+5,M=5e3+5,INF=1e9,mod=998244353;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
ll sp[N],sm[N],ad[N];
int n,q,A,B,x[N];
#define ls (k<<1)
#define rs (k<<1|1)
#define mid (l+r>>1)
#define lson ls,l,mid
#define rson rs,mid+1,r
il void mtg(int k,ll v){sp[k]+=v;sm[k]+=v;ad[k]+=v;}
il void pd(int k){if(!ad[k])return;mtg(ls,ad[k]);mtg(rs,ad[k]);ad[k]=0;}
il void pu(int k){sp[k]=min(sp[ls],sp[rs]);sm[k]=min(sm[ls],sm[rs]);}
void add(int x,int y,ll val,int k=1,int l=1,int r=n){
	if(x>y)return;
	if(l==x&&r==y){mtg(k,val);return;}
	pd(k);
	if(y<=mid)add(x,y,val,lson);else
	if(x> mid)add(x,y,val,rson);else
		add(x,mid,val,lson),add(mid+1,y,val,rson);
	pu(k);
}
ll ask(int x,int y,int isp,int k=1,int l=1,int r=n){
	if(x>y)return linf;
	if(l==x&&r==y)return isp?sp[k]:sm[k];
	pd(k);
	if(y<=mid)return ask(x,y,isp,lson);else
	if(x> mid)return ask(x,y,isp,rson);else
		return min(ask(x,mid,isp,lson),ask(mid+1,y,isp,rson));
}
void modi(int x,ll val,int typ,int k=1,int l=1,int r=n){
	if(l==r){
		if(typ)sp[k]=val;else sm[k]=val;
		return;
	}pd(k);
	if(x<=mid)modi(x,val,typ,lson);else
		modi(x,val,typ,rson);
	pu(k);
}
void build(int k=1,int l=1,int r=n){
	if(l==r){sm[k]=sp[k]=linf;return;}
	build(lson);build(rson);
	pu(k);
}
int main(){
	read(n,q);read(A,B);
	rep(i,1,q)read(x[i]);
	x[0]=B;
	build();
	modi(A,A,1);
	modi(A,-A,0);
	rep(i,1,q){
		ll tmp=min(ask(1,x[i],0)+x[i],ask(x[i]+1,n,1)-x[i]);
		add(1,x[i-1]-1,abs(x[i]-x[i-1]));
		add(x[i-1]+1,n,abs(x[i]-x[i-1]));
		modi(x[i-1],tmp+x[i-1],1);
		modi(x[i-1],tmp-x[i-1],0);
	}
	ll ans=linf;
	rep(i,1,n)gmin(ans,ask(i,i,0)+i);
	cout<<ans<<endl;
}

Measured memory_bytes: 19456