/**
    *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];
}


Measured memory_bytes: 32256