// Slower C++ solution:
#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";

}


// Faster C++ solution for the same problem (measured speedup: 4.241206143891757x):
/**

    *Makacha

**/

#include <bits/stdc++.h>

using namespace std;



template <typename T> inline void read (T &x) {bool b = 0; char c; while (!isdigit (c = getchar()) && c != '-');

if (c == '-') c = getchar(), b = 1; x = c - 48; while (isdigit(c = getchar())) x = (x<<3) + (x<<1) + c - 48; if (b)x=-x;}

template <typename T> inline void wrip(T x) {if (x > 9) wrip(x / 10); putchar(x%10 + 48); }



template <typename T> inline void write(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar(' ');}

template <typename T> inline void writeln(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar('\n');}

inline char readch() {char c; do c = getchar(); while (c == '\n' || c == ' '); return c;}

inline void reads(string &s) {char c; while((c=getchar())==' '||c =='\n'); s=c; while((c=getchar())!=' '&&c!='\n') s+=c;}

inline void getlines(string &s) {char c; while((c=getchar())=='\n'); s=c; while((c=getchar())!='\n') s+=c;}

typedef const int csint;



#define fi first

#define se second

#define mp make_pair

typedef long long ll;

typedef long double ld;

typedef pair <int, int> ii;

typedef vector <int> vi;



const ld pi = acos(-1);

const ll inf = 1e16;

const int mod = 1e9 + 7,

N = 1e6 + 11;



class tree{

private:

    int l, r, m;

    tree *left, *right;

public:

    ll rem, ans[3];

    inline tree() {

        left = right = NULL;

        rem = 0;

        ans[0] = ans[1] = ans[2] = inf;

    }

    inline tree(csint &u, csint &v) {

        left = right = NULL;

        l = u, r = v, m = u + v >> 1;

        rem = 0;

        ans[0] = ans[1] = ans[2] = inf;

    }

    void Build() {

        if (l == r)

            return;

        left = new tree(l, m);

        left->Build();

        right = new tree(m + 1, r);

        right->Build();

    }

    inline void Add(ll val) {

        rem += val;

        ans[0] += val;

        ans[1] += val;

        ans[2] += val;

    }

    inline void PushDown() {

        if (rem) {

            left->Add(rem);

            right->Add(rem);

            rem = 0;

        }

    }

    inline void PushUp() {

        for (int i = 0; i < 3; i++)

            ans[i] = min(left->ans[i], right->ans[i]);

    }

    void Update(int pos, ll val) {

        if (l == r) {

            rem = val;

            ans[0] = val;

            ans[1] = val - l;

            ans[2] = val + l;

            return;

        }

        PushDown();

        if (pos <= m)

            left->Update(pos, val);

        else

            right->Update(pos, val);

        PushUp();

    }

    ll Get(int u, int v, int type) {

        if (l > v || r < u)

            return inf;

        if (u <= l && r <= v)

            return ans[type];

        PushDown();

        ll res = min(left->Get(u, v, type),

                     right->Get(u, v, type));

        PushUp();

        return res;

    }

};

int n, m, A, B;

int a[N];

int main() {

    #ifdef makacha

        freopen("m.inp", "r", stdin);

        freopen("m.out", "w", stdout);

    #endif // makacha

    read(n);

    read(m);

    read(A);

    read(B);

    tree *it = new tree(1, n);

    it->Build();

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

        read(a[i]);

    it->Update(A, abs(B - a[1]));

    it->Update(B, abs(A - a[1]));

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

        ll tmp = it->Get(a[i - 1], a[i - 1], 0) + abs(a[i] - a[i - 1]);

        tmp = min(tmp, it->Get(1, a[i], 1) + a[i]);

        tmp = min(tmp, it->Get(a[i], n, 2) - a[i]);

        it->Add(abs(a[i] - a[i - 1]));

        it->Update(a[i - 1], tmp);

    }

    cout << it->ans[0];

}