#include <bits/stdc++.h>
using namespace std;

template<class Monoid, class OperatorMonoid, class FunctionM, class FunctionMO, class FunctionO>
struct LazySegmentTree {
    int N; vector<Monoid> segment; vector<OperatorMonoid> lazy;
    const FunctionM FuncM; const FunctionMO FuncMO; const FunctionO FuncO;
    const Monoid idM; const OperatorMonoid idOM;

    LazySegmentTree(int n, const FunctionM FuncM, const FunctionMO FuncMO, const FunctionO FuncO,
        const Monoid idM, const OperatorMonoid idOM)
    : FuncM(FuncM), FuncMO(FuncMO), FuncO(FuncO), idM(idM), idOM(idOM) {
        N = 1;
        while (N < n) N <<= 1;
        segment.assign(2 * N, idM); lazy.assign(2 * N, idOM);
    }

    LazySegmentTree(int n, const FunctionM FuncM, const FunctionMO FuncMO, const FunctionO FuncO,
        const Monoid idM, const OperatorMonoid idOM, const Monoid initVal)
    : FuncM(FuncM), FuncMO(FuncMO), FuncO(FuncO), idM(idM), idOM(idOM) {
        N = 1;
        while (N < n) N <<= 1;
        segment.assign(2 * N, initVal); lazy.assign(2 * N, idOM);
    }

    void set(int num, Monoid x) {
        segment[N + num] = x;
    }
    void build() {
        for (int k = N - 1; k > 0; k--) {
            segment[k] = FuncM(segment[2*k], segment[2*k+1]);
        }
    }

    inline void propagate(int k, int len){
        if (lazy[k] != idOM) {
            if (k < N) {
                lazy[2*k] = FuncO(lazy[2*k], lazy[k]);
                lazy[2*k+1] = FuncO(lazy[2*k+1], lazy[k]);
            }
            segment[k] = FuncMO(segment[k], lazy[k], len);
            lazy[k] = idOM;
        }
    }

    // update:[a, b)
    Monoid update(int a, int b, const OperatorMonoid x) {
        return update(a, b, x, 1, 0, N);
    }
    Monoid update(int a, int b, const OperatorMonoid x, int k, int l, int r){
        propagate(k, r-l);
        if (b <= l || r <= a) {
            return segment[k];
        } else if (a <= l && r <= b) {
            lazy[k] = FuncO(lazy[k], x);
            propagate(k, r-l);
            return segment[k];
        } else {
            int m = (l + r) / 2;
            return segment[k] = FuncM(update(a, b, x, 2*k, l, m), update(a, b, x, 2*k+1, m, r));
        }
    }

    // query:[a, b)
    Monoid query(int a, int b) {
        return query(a, b, 1, 0, N);
    }
    Monoid query(int a, int b, int k, int l, int r) {
        propagate(k, r-l);
        if (b <= l || r <= a) {
            return idM;
        } else if (a <= l && r <= b) {
            return segment[k];
        } else {
            int m = (l + r) / 2;
            return FuncM(query(a, b, 2*k, l, m), query(a, b, 2*k+1, m, r));
        }
    }

    // 0-indexed numbering;
    inline Monoid operator[](const int &k) {
        return query(k, k + 1);
    }
};

long long inf = 1e17;

auto F = [&](long long a, long long b) {return min(a, b);};
auto G = [&](long long a, long long b, int len) { return min(a + b, inf);};
auto H = [&](long long a, long long b) { return a + b; };

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, q, a, b; cin >> n >> q >> a >> b; a--, b--;
    LazySegmentTree<long long, long long, decltype(F), decltype(G), decltype(H)> 
        lstplus(n, F, G, H, inf, 0), lstminus(n, F, G, H, inf, 0);
    vector<int> x(q+1, b);
    for (int i = 0; i < q; i++) { cin >> x[i]; x[i]--; }
    auto init_a = abs(b-x[0]), init_b = abs(a-x[0]);
    lstplus.update(a, a+1, init_a+a-lstplus[a]);
    lstminus.update(a, a+1, init_a-a-lstminus[a]);
    lstplus.update(b, b+1, init_b+b-lstplus[b]);
    lstminus.update(b, b+1, init_b-b-lstminus[b]);
    for (int i = 1; i < q; i++) {
        int prev = x[i-1], curr = x[i];
        auto minus = lstminus.query(0, curr) + curr;
        auto plus = lstplus.query(curr, n) - curr;
        auto upd = min(minus, plus);
        lstplus.update(0, n, abs(curr-prev));
        lstminus.update(0, n, abs(curr-prev));
        auto plp = lstplus[prev]; auto pmp = lstminus[prev];
        lstplus.update(prev, prev+1, upd+prev-plp);
        lstminus.update(prev, prev+1, upd-prev-pmp);
    }
    long long ans = inf;
    for (int i = 0; i < n; i++) {
        ans = min(ans, lstplus[i]-i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 19456