#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 2 * (int)1e5 + 10;
const ll INF = 1e18;
struct SG {
    ll t[4 * maxN];
    ll lazy[4 * maxN];
    SG() {
        for (int i = 0; i < 4 * maxN; i++) {
            t[i] = lazy[i] = 0;
        }
    }

    void build(int v, int tl, int tr) {
        if (tl == tr) {
            t[v] = INF;
            return;
        }
        int tm = (tl + tr) / 2;
        build(2 * v, tl, tm);
        build(2 * v + 1, tm + 1, tr);
        t[v] = min(t[2 * v], t[2 * v + 1]);
    }

    void upd(int v, ll by) {
        lazy[v] += by;
        t[v] += by;
    }

    void merge(int v) {
        t[v] = min(t[2 * v], t[2 * v + 1]);
    }

    void push(int v, int tl, int tr) {
        if (tl != tr && lazy[v] != 0) {
            upd(2 * v, lazy[v]);
            upd(2 * v + 1, lazy[v]);
        }
        lazy[v] = 0;
    }

    void upd(int v, int tl, int tr, int l, int r, ll by) {
        if (l > tr || r < tl) return;
        if (l <= tl && tr <= r) {
            upd(v, by);
            push(v, tl, tr);
            return;
        }
        push(v, tl, tr);
        int tm = (tl + tr) / 2;
        upd(2 * v, tl, tm, l, r, by);
        upd(2 * v + 1, tm + 1, tr, l, r, by);
        merge(v);
    }

    ll get(int v, int tl, int tr, int l, int r) {
        if (l > tr || r < tl) return INF;
        if (l <= tl && tr <= r) {
            return t[v];
        }
        push(v, tl, tr);
        int tm = (tl + tr) / 2;
        return min(get(2 * v, tl, tm, l, r), get(2 * v + 1, tm + 1, tr, l, r));
    }

    void set(int v, int tl, int tr, int pos, ll val) {
        if (tl == tr) {
            t[v] = min(t[v], val);
            return;
        }
        push(v, tl, tr);
        int tm = (tl + tr) / 2;
        if (pos <= tm) set(2 * v, tl, tm, pos, val);
        else set(2 * v + 1, tm + 1, tr, pos, val);
        merge(v);
    }
}add, de, init;
int n, q;
int a, b;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n >> q;
    cin >> a >> b;
    add.build(1, 1, n);
    de.build(1, 1, n);
    init.build(1, 1, n);
    int prv = 0;
    for (int i = 1; i <= q; i++) {
        int x;
        cin >> x;
        if (i == 1) {
            prv = x;
            add.set(1, 1, n, a, a + abs(x - b));
            de.set(1, 1, n, a, -a + abs(x - b));
            init.set(1, 1, n, a, abs(x - b));
            add.set(1, 1, n, b, b + abs(x - a));
            de.set(1, 1, n, b, -b + abs(x - a));
            init.set(1, 1, n, b, abs(x - a));
        }
        else {
            ll val = min(de.get(1, 1, n, 1, x) + x, add.get(1, 1, n, x, n) - x);
//            cout << de.get(1, 1, n, 1, x) + x << " HER " << endl;
//            cout << val << " " << x << " " << prv << endl;
            add.upd(1, 1, n, 1, n, abs(x - prv));
            de.upd(1, 1, n, 1, n, abs(x - prv));
            init.upd(1, 1, n, 1, n, abs(x - prv));
            add.set(1, 1, n, prv, val + prv);
            de.set(1, 1, n, prv, val - prv);
            init.set(1, 1, n, prv, val);
            prv = x;
        }
    }
    cout << init.get(1, 1, n, 1, n) << '\n';
    return 0;
}

Measured memory_bytes: 37760