#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define L (x<<1)
#define R (x<<1|1)
#define mid ((l+r)>>1)
#define inf 0x3f3f3f3f3f3f3f3fll
#define MM (1<<20)
#define MN 200005
using namespace std;
inline int in(){
    int x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
ll ml[MM],mr[MM],mv[MM],tag[MM];
ll val,d;
int n,q,a,b,x,y;
inline void up(int x){
	ml[x]=min(ml[L],ml[R]);
	mr[x]=min(mr[L],mr[R]);
	mv[x]=min(mv[L],mv[R]);
}
inline void pushdown(int x,int l,int r){
	if (l==r||(!tag[x])) return;
	ml[L]+=tag[x];mr[L]+=tag[x];mv[L]+=tag[x];tag[L]+=tag[x];
	ml[R]+=tag[x];mr[R]+=tag[x];mv[R]+=tag[x];tag[R]+=tag[x];tag[x]=0;
}
inline void build(int x,int l,int r){
	if (l==r){
		mv[x]=inf;ml[x]=mv[x]+l;mr[x]=mv[x]-l;return;
	}build(L,l,mid);build(R,mid+1,r);up(x);
}
inline void update(int x,int l,int r,int p,ll v){
	if (l==r){
		mv[x]=min(mv[x],v);ml[x]=mv[x]+l;mr[x]=mv[x]-l;return;
	}pushdown(x,l,r);
	if (p<=mid) update(L,l,mid,p,v);
	else update(R,mid+1,r,p,v);up(x);
}
inline ll query1(int x,int l,int r,int a,int b){
	if (a<=l&&b>=r) return ml[x];pushdown(x,l,r);
	if (b<=mid) return query1(L,l,mid,a,b);
	if (a>mid) return query1(R,mid+1,r,a,b);
	return min(query1(L,l,mid,a,mid),query1(R,mid+1,r,mid+1,b));
}
inline ll query2(int x,int l,int r,int a,int b){
	if (a<=l&&b>=r) return mr[x];pushdown(x,l,r);
	if (b<=mid) return query2(L,l,mid,a,b);
	if (a>mid) return query2(R,mid+1,r,a,b);
	return min(query2(L,l,mid,a,mid),query2(R,mid+1,r,mid+1,b));
}
int main()
{
	n=in();q=in();a=in();b=in();
	build(1,1,n);update(1,1,n,b,0);y=a;
	for (int i=1;i<=q;++i){
		x=in();
		val=min(query2(1,1,n,1,x)+x,query1(1,1,n,x,n)-x);
		d=abs(x-y);ml[1]+=d;mr[1]+=d;mv[1]+=d;tag[1]+=d;
		update(1,1,n,y,val);y=x;
	}printf("%lld",mv[1]);return 0;
}