#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

const int NMAX = 2e5 + 5;

typedef long long LL;

class SegmentTree
{
public:
    LL aint[4 * NMAX];
    LL add[4 * NMAX];
    LL v[NMAX];
    int N;
    LL ans;

    void init(int _N, LL _v[])
    {
        N = _N;
        for(int i = 1; i <= N; i++) v[i] = _v[i];
        B(1, 1, N);
    }

    void B(int nod, int st, int dr)
    {
        add[nod] = 0;
        if(st == dr)
        {
            aint[nod] = v[st];
            return;
        }

        int mij = st + (dr - st) / 2;
        B(nod * 2, st, mij);
        B(nod * 2 + 1, mij + 1, dr);

        aint[nod] = min(aint[nod * 2], aint[nod * 2 + 1]);
    }

    void U(int st, int dr, LL val) { U(1, 1, N, st, dr, val); }

    void U(int pos, LL val) { U(1, 1, N, pos, val); }

    void U(int nod, int st, int dr, int sti, int dri, LL val)
    {
        if(sti <= st && dr <= dri)
        {
            aint[nod] += val;
            add[nod] += val;
            return;
        }

        int mij = st + (dr - st) / 2;
        if(add[nod])
        {
            U(nod * 2, st, mij, st, dr, add[nod]);
            U(nod * 2 + 1, mij + 1, dr, st, dr, add[nod]);
            add[nod] = 0;
        }

        if(sti <= mij)  U(nod * 2, st, mij, sti, dri, val);
        if(mij < dri)   U(nod * 2 + 1, mij + 1, dr, sti, dri, val);

        aint[nod] = min(aint[nod * 2], aint[nod * 2 + 1]);
    }

    void U(int nod, int st, int dr, int pos, LL val)
    {
        if(st == dr)
        {
            aint[nod] = val;
            return;
        }

        int mij = st + (dr - st) / 2;
        if(add[nod])
        {
            U(nod * 2, st, mij, st, dr, add[nod]);
            U(nod * 2 + 1, mij + 1, dr, st, dr, add[nod]);
            add[nod] = 0;
        }

        if(pos <= mij)  U(nod * 2, st, mij, pos, val);
        else            U(nod * 2 + 1, mij + 1, dr, pos, val);

        aint[nod] = min(aint[nod * 2], aint[nod * 2 + 1]);
    }

    void Q(int nod, int st, int dr, int sti, int dri)
    {
        if(sti <= st && dr <= dri)
        {
            ans = min(ans, aint[nod]);
            return;
        }

        int mij = st + (dr - st) / 2;
        if(add[nod])
        {
            U(nod * 2, st, mij, st, dr, add[nod]);
            U(nod * 2 + 1, mij + 1, dr, st, dr, add[nod]);
            add[nod] = 0;
        }

        if(sti <= mij)  Q(nod * 2, st, mij, sti, dri);
        if(mij < dri)   Q(nod * 2 + 1, mij + 1, dr, sti, dri);
    }

    LL q(int st, int dr)
    {
        if(st > dr) return (1LL << 60);
        ans = 1LL << 60;
        Q(1, 1, N, st, dr);
        return ans;
    }
};

SegmentTree aint, amns, apls;

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    int N, M, A, B;
    scanf("%d%d%d%d", &N, &M, &A, &B);

    LL v[NMAX];
    for(int i = 1; i <= N; i++) v[i] = 1LL << 40;
    v[B] = 0;
    aint.init(N, v);

    for(int i = 1; i <= N; i++) v[i] -= i;
    amns.init(N, v);

    for(int i = 1; i <= N; i++) v[i] += 2 * i;
    apls.init(N, v);

    for(int i = 1; i <= M; i++)
    {
        int p; scanf("%d", &p);
        int dst = abs(p - A);

        LL st = amns.q(1, p);
        LL dr = apls.q(p, N);
        LL val = min(st + p, dr - p);

        aint.U(1, N, dst); amns.U(1, N, dst); apls.U(1, N, dst);
        aint.U(A, val); amns.U(A, val - A); apls.U(A, val + A);

        A = p;
    }

    LL ans = aint.q(1, N);
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 41984