// Original C++ solution (slower):
#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";

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

#define maxn 200010

const long long INF=1e18;

template <typename T>inline T read()

{

    register T sum=0;

    register char cc=getchar();

    int sym=1;

    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();

    if(cc=='-')sym=-1,cc=getchar();

    sum=sum*10+cc-'0';

    cc=getchar();

    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();

    return sym*sum;

}

template <typename T>inline T read(T &a)

{

    a=read<T>();

    return a;

}

template <typename T,typename... Others> inline void read(T& a, Others&... b)

{

    a=read(a);

	read(b...);

}

int n,m,A,B,x[maxn];

long long f[maxn],tag[maxn<<2],val[maxn<<2][3];

void Effect(int k,long long v)

{

	for(int i:{0,1,2})

		val[k][i]+=v;

	tag[k]+=v;

}

void down(int k)

{

	if(tag[k])

	{

		Effect(k<<1,tag[k]);

		Effect(k<<1|1,tag[k]);

		tag[k]=0;

	}

}

void update(int k)

{

	for(int i:{0,1,2})

		val[k][i]=min(val[k<<1][i],val[k<<1|1][i]);

}

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

{

	if(l==r)

	{

		val[k][0]=f[l];

		val[k][1]=f[l]+l;

		val[k][2]=f[l]-l;

		return ;

	}

	int mid=(l+r)>>1;

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

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

	update(k);

}

void change(int k,int l,int r,int x,long long y)

{

	if(l==r)

	{

		if(y<val[k][0])

		{

			val[k][0]=y;

			val[k][1]=y+l;

			val[k][2]=y-l;

		}

		return ;

	}

	down(k);

	int mid=(l+r)>>1;

	if(x<=mid)change(k<<1,l,mid,x,y);

	else change(k<<1|1,mid+1,r,x,y);

	update(k);

}

long long query(int k,int l,int r,int x,int y,int op)

{

	if(l>=x&&r<=y)

		return val[k][op];

	down(k);

	int mid=(l+r)>>1;

	long long res=INF;

	if(x<=mid)res=min(res,query(k<<1,l,mid,x,y,op));

	if(y>mid)res=min(res,query(k<<1|1,mid+1,r,x,y,op));

	return res;

}

int main()

{

	read(n,m,A,B);

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

		read(x[i]);

	memset(f+1,0x7f,sizeof(long long)*n);

	f[A]=min(f[A],1ll*abs(B-x[1]));

	f[B]=min(f[B],1ll*abs(A-x[1]));

	build(1,1,n);

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

	{

		long long v=query(1,1,n,1,x[i],2)+x[i];

		if(x[i]<n)v=min(v,query(1,1,n,x[i]+1,n,1)-x[i]);

		Effect(1,abs(x[i]-x[i-1]));

		change(1,1,n,x[i-1],v);

	}

	printf("%lld\n",val[1][0]);

    return 0;

}


// Fastest known solution for this problem: