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

using namespace std;

#define y1 A2Dalek

#define y0 Cyberman

#define yn RoseTyler

#define j1 JackHarkness

#define fs first

#define sd second

const int N=2e5;

const long long oo=1e16+5;

int du[]={-1,0,0,1};

int dv[]={0,-1,1,0};

const long long mod=1e9+7;

typedef pair<int,int> ii;

typedef pair<int,ii> iii;

long long sqr(long long x) {return x*x;}

int getbit(int state, int i) {return ((state>>i)&1);}



int n,nq,A,B,q[N+5];

long long res=oo;

struct IT

{

    long long f[4*N+5];

    long long lz[4*N+5];

    long long a[N+5];

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

    {

        if (l>r) return;

        if (l==r) {f[id]=a[l]; return;}

        int mid=(l+r)/2;

        build(id*2,l,mid); build(id*2+1,mid+1,r);

        f[id]=min(f[id*2],f[id*2+1]);

    }

    void down(int id)

    {

        long long val=lz[id]; lz[id]=0;

        f[id*2]+=val; f[id*2+1]+=val;

        lz[id*2]+=val; lz[id*2+1]+=val;

    }

    void update(int id, int l, int r, int u, long long val)

    {

        if (l>u || r<u || l>r) return;

        if (l==r)

        {

            f[id]=min(f[id],val);

            return;

        }

        int mid=(l+r)/2;

        down(id);

        update(id*2,l,mid,u,val); update(id*2+1,mid+1,r,u,val);

        f[id]=min(f[id*2],f[id*2+1]);

    }

    long long get(int id, int l, int r, int u, int v)

    {

        if (l>r || l>v || r<u) return oo;

        if (u<=l && r<=v) return f[id];

        int mid=(l+r)/2;

        down(id);

        return min(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v));

    }

} tru,cong;

int main()

{

	//freopen("Many Moves.inp","r",stdin);

	//freopen("Many Moves.out","w",stdout);

	ios_base::sync_with_stdio(false);

    cin>>n>>nq;

    cin>>A>>B;

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

    {

        tru.a[i]=abs(B-i)-i;

        cong.a[i]=abs(B-i)+i;

    }

    tru.build(1,1,n); cong.build(1,1,n);

    q[0]=A;

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

    {

        cin>>q[i];

        long long val=abs(q[i]-q[i-1]);

        long long now=min(tru.get(1,1,n,1,q[i])+q[i], cong.get(1,1,n,q[i],n)-q[i]);

        tru.f[1]+=val; cong.f[1]+=val;

        tru.lz[1]+=val; cong.lz[1]+=val;

        tru.update(1,1,n,q[i-1],now-q[i-1]);

        cong.update(1,1,n,q[i-1],now+q[i-1]);

    }

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

    {

        res=min(res,tru.get(1,1,n,i,i)+i);

    }

    cout<<res;

	return 0;

}


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

#include<cstring>

#include<algorithm>

using namespace std;

inline int gi()

{

	char c;int num=0,flg=1;

	while((c=getchar())<'0'||c>'9')if(c=='-')flg=-1;

	while(c>='0'&&c<='9'){num=num*10+c-48;c=getchar();}

	return num*flg;

}

#define N 200005

#define LL long long

#define lc i<<1

#define rc i<<1|1

const LL INF=0x3f3f3f3f3f3f3f3fll;

int pos[N],A,B,n,Q;

struct node{

	int l,r;

	LL mi1,mi2,la;

}a[N<<2];

void cal(int i,LL k){a[i].mi1+=k;a[i].mi2+=k;a[i].la+=k;}

void pushdown(int i)

{

	if(a[i].la&&a[i].l<a[i].r){

		cal(lc,a[i].la);cal(rc,a[i].la);

		a[i].la=0;

	}

}

void pushup(int i)

{

	a[i].mi1=min(a[lc].mi1,a[rc].mi1);

	a[i].mi2=min(a[lc].mi2,a[rc].mi2);

}

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

{

	a[i].l=l;a[i].r=r;

	if(l==r){

		a[i].mi1=INF;a[i].mi2=INF;

		return;

	}

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

	build(lc,l,mid);build(rc,mid+1,r);

	pushup(i);

}

void insert(int i,int l,int r,LL k)

{

	if(a[i].l>r||a[i].r<l)return;

	pushdown(i);

	if(l<=a[i].l&&a[i].r<=r){cal(i,k);return;}

	insert(lc,l,r,k);insert(rc,l,r,k);

	pushup(i);

}

void modify(int i,int x,LL k)

{

	if(a[i].l>x||a[i].r<x)return;

	pushdown(i);

	if(x==a[i].l&&a[i].r==x){a[i].mi1=min(a[i].mi1,k-x);a[i].mi2=min(a[i].mi2,k+x);return;}

	modify(lc,x,k);modify(rc,x,k);

	pushup(i);

}

LL query1(int i,int l,int r)

{

	if(a[i].l>r||a[i].r<l)return INF;

	pushdown(i);

	if(l<=a[i].l&&a[i].r<=r)return a[i].mi1;

	return min(query1(lc,l,r),query1(rc,l,r));

}

LL query2(int i,int l,int r)

{

	if(a[i].l>r||a[i].r<l)return INF;

	pushdown(i);

	if(l<=a[i].l&&a[i].r<=r)return a[i].mi2;

	return min(query2(lc,l,r),query2(rc,l,r));

}

LL query(int i)

{

	if(a[i].l==a[i].r)return a[i].mi1+a[i].l;

	pushdown(i);

	return min(query(lc),query(rc));

}

int ab(int x){return x<0?-x:x;}

int main()

{

	int i;LL f;

	n=gi();Q=gi();A=gi();B=gi();

	build(1,1,n);

	pos[0]=A;modify(1,B,0);

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

		pos[i]=gi();

		f=min(query1(1,1,pos[i])+pos[i],query2(1,pos[i]+1,n)-pos[i]);

		insert(1,1,n,ab(pos[i]-pos[i-1]));

		modify(1,pos[i-1],f);

	}

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

}

// Fastest known solution for this problem: