#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

const int64_t LINF = 1LL << 62;

class SegmentTree {
public:
    SegmentTree(int _n):
        tleft(vector<int64_t>(4 * _n + 5, LINF)),
        tright(vector<int64_t>(4 * _n + 5, LINF)),
        lazy(vector<int64_t>(4 * _n + 5, 0)),
        n(_n) {}
    void addAll(int64_t value) {
        lazy[0] += value;
    }
    int64_t queryLeft(int right) {
        return queryLeft(0, 0, n - 1, right);
    }
    int64_t queryRight(int left) {
        return queryRight(0, 0, n - 1, left);
    }
    void update(int pos, int64_t val) {
        update(0, 0, n - 1, pos, val);
    }
private:
    vector<int64_t> tleft, tright, lazy;
    int n;
    
    void split(int node, int left, int right) {
        if (lazy[node] != 0) {
            tleft[node] += lazy[node];
            tleft[node] = min(tleft[node], LINF);
            tright[node] += lazy[node];
            tright[node] = min(tright[node], LINF);
            if (left < right) {
                lazy[2 * node + 1] += lazy[node];
                lazy[2 * node + 2] += lazy[node];
            }
            lazy[node] = 0;
        }
    }
    int64_t queryLeft(int node, int left, int right, int rq) {
        split(node, left, right);
        if (right <= rq) {
            return tleft[node];
        } else {
            int mid = (left + right) / 2;
            int64_t ret = queryLeft(2 * node + 1, left, mid, rq);
            if (rq > mid) {
                ret = min(ret, queryLeft(2 * node + 2, mid + 1, right, rq));
            }
            return ret;
        }
    }
    int64_t queryRight(int node, int left, int right, int lq) {
        split(node, left, right);
        if (lq <= left) {
            return tright[node];
        } else {
            int mid = (left + right) / 2;
            int64_t ret = queryRight(2 * node + 2, mid + 1, right, lq);
            if (lq <= mid) {
                ret = min(ret, queryRight(2 * node + 1, left, mid, lq));
            }
            return ret;
        }
    }

    void update(int node, int left, int right, int pos, int64_t value) {
        split(node, left, right);
        if (left == right) {
            tleft[node] = min(tleft[node], value - left);
            tright[node] = min(tright[node], value + left);
        } else {
            int mid = (left + right) / 2;
            if (pos <= mid) {
                update(2 * node + 1, left, mid, pos, value);
            } else {
                update(2 * node + 2, mid + 1, right, pos, value);
            }
            split(2 * node + 1, left, mid);
            split(2 * node + 2, mid + 1, right);
            tleft[node] = min(tleft[2 * node + 1], tleft[2 * node + 2]);
            tright[node] = min(tright[2 * node + 1], tright[2 * node + 2]);
        }
    }
};

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, q, a;
    cin >> n >> q >> a;

    SegmentTree t(n + 1);
    t.update(a, 0);
    vector<int> A(q + 1);
    cin >> A[0];
    int64_t ans = 0;
    int64_t prev = 0;
    for (int i = 1; i <= q; ++i) {
        cin >> A[i];
        prev = ans;
        int64_t x = t.queryLeft(A[i]);
        int64_t v = A[i] + x;
        x = t.queryRight(A[i]);
        v = min(v, -A[i] + x);

        int64_t add = abs(A[i] - A[i - 1]);
        t.addAll(add);
        t.update(A[i - 1], v);
        ans = min(prev + add, v);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 21888