// Slower C++ solution:
#include<cmath>

#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

#define sqz main

#define ll long long

#define reg register int

#define rep(i, a, b) for (reg i = a; i <= b; i++)

#define per(i, a, b) for (reg i = a; i >= b; i--)

#define travel(i, u) for (reg i = head[u]; i; i = edge[i].next)

const ll INF = 1e15;

const int N = 800000;

const double eps = 1e-6, phi = acos(-1);

ll mod(ll a, ll b) {if (a >= b || a < 0) a %= b; if (a < 0) a += b; return a;}

ll read(){ ll x = 0; int zf = 1; char ch; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();

if (ch == '-') zf = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;}

void write(ll y) { if (y < 0) putchar('-'), y = -y; if (y > 9) write(y / 10); putchar(y % 10 + '0');}

int x[N / 4 + 5];

struct node

{

    ll val[2][N + 5];

    int left[N + 5], right[N + 5];

    ll tag[N + 5];

    inline void down(int u)

    {

        val[0][u + u] += tag[u], val[0][u + u + 1] += tag[u];

        val[1][u + u] += tag[u], val[1][u + u + 1] += tag[u];

        tag[u + u] += tag[u], tag[u + u + 1] += tag[u];

        tag[u] = 0;

    }

    inline void up(int u)

    {

        val[0][u] = min(val[0][u + u] , val[0][u + u + 1]);

        val[1][u] = min(val[1][u + u] , val[1][u + u + 1]);

    }

    

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

    {

        left[u] = l, right[u] = r, val[0][u] = val[1][u] = INF, tag[u] = 0;

        if (l == r) return;

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

        build(u + u, l, mid);

        build(u + u + 1, mid + 1, r);

    }

    

    void modify(int u, int pos, ll v)

    {

        int l = left[u], r = right[u], mid = (l + r) >> 1;

        if (l == r)

        {

            val[0][u] = min(val[0][u], v - pos), val[1][u] = min(val[1][u], v + pos);

            return;

        }

        down(u);

        if (pos <= mid) modify(u + u, pos, v);

        else modify(u + u + 1, pos, v);

        up(u);

    }

    

    ll query(int t, int u, int x, int y)

    {

        int l = left[u], r = right[u], mid = (l + r) >> 1; ll T = INF;

        if (x <= l && y >= r) return val[t][u];

        down(u);

        if (x <= mid) T = min(T, query(t, u + u, x, y));

        if (y > mid) T = min(T, query(t, u + u + 1, x, y));

        return T;

    }

    

    ll find(int u)

    {

        int l = left[u], r = right[u], mid = (l + r) >> 1;

        if (l == r) return min(val[0][u] + l, val[1][u] - l);

        down(u);

        return min(find(u + u), find(u + u + 1));

    }

}Segment_tree;

int sqz()

{

    int n = read(), q = read(), pos = read(); x[0] = read();

    Segment_tree.build(1, 1, n);

    Segment_tree.modify(1, pos, 0);

    rep(i, 1, q)

    {

        x[i] = read();

        ll now = min(Segment_tree.query(0, 1, 1, x[i]) + x[i], Segment_tree.query(1, 1, x[i], n) - x[i]);

        Segment_tree.tag[1] += abs(x[i] - x[i - 1]), Segment_tree.val[0][1] += abs(x[i] - x[i - 1]), Segment_tree.val[1][1] += abs(x[i] - x[i - 1]);

        Segment_tree.modify(1, x[i - 1], now);

    }

    printf("%lld\n", Segment_tree.find(1));

}

// Faster C++ solution for the same problem (measured speedup: 5.105537949331247x):
#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));

}