#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define psb push_back
#define ppb pop_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef double DB;
typedef pair<int,int> PII;
template <typename T> void gi(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void gi(T1 &angka1,T2 &angka2){
	gi(angka1);gi(angka2);
}

const int MAXN = 200000;
const int MAXQ = 200000;
int n, q;
int pos[MAXN + 5];
void readInput() {
    gi(n, q);
    gi(pos[0], pos[1]);
    for (int i = 2; i <  q + 2; ++i) {
        gi(pos[i]);
    }
}

LL pre[MAXN + 5];
void fillPre() {
    pre[0] = 0;
    for (int i = 1; i < q + 2; ++i) {
        pre[i] = pre[i - 1] + abs(pos[i] - pos[i - 1]);
    }
}

const int treesize = 4 * MAXN;
pair<LL, LL> tree[treesize + 5];
const LL INF = 1000000000000LL;
void buildTree(int l, int r, int idx) {
    tree[idx] = mp(INF, INF);
    if (l == r) return;
    int mid = (l + r) >> 1;
    buildTree(l, mid, idx << 1);
    buildTree(mid + 1, r, (idx << 1) | 1);
}

void buildTree() {
    buildTree(1, n, 1);
}

pair<LL, LL> combine(pair<LL, LL> lVal, pair<LL, LL> rVal) {
    return mp(min(lVal.fi, rVal.fi), min(lVal.se, rVal.se));
}

void update(int l, int r, int idx, int pos, pair<LL, LL> val) {
    if (l == r) {
        assert(l == pos);
        tree[idx] = combine(tree[idx], val);
        return;
    }

    int mid = (l + r) >> 1;
    if (pos <= mid) {
        update(l, mid, idx << 1, pos, val);
    } else {
        update(mid + 1, r, (idx << 1) | 1, pos, val);
    }

    tree[idx] = combine(tree[idx << 1], tree[(idx << 1) | 1]);
}

void update(int pos, pair<LL, LL> val) {
    update(1, n, 1, pos, val);
}

// type == 0, first val
// type == 1, second val
LL query(int type, int l, int r, int idx, int queryL, int queryR) {
    if (queryL <= l && r <= queryR) {
        if (type == 0) {
            return tree[idx].fi;
        } else {
            return tree[idx].se;
        }
    }

    if (queryL > r || queryR < l) {
        return INF;
    }

    int mid = (l + r) >> 1;
    return min(query(type, l, mid, idx << 1, queryL, queryR),
        query(type, mid + 1, r, (idx << 1) | 1, queryL, queryR));
}

LL query(int type, int queryL, int queryR) {
    return query(type, 1, n, 1, queryL, queryR);
}

LL dp[MAXQ + 5];
LL findAns() {
    dp[q + 2] = 0;
    for (int i = q + 1; i >= 1; --i) {
        int a = i - 1;
        int b = i;
        dp[i] = pre[q + 1] - pre[b];
        dp[i] = min(dp[i], query(0, pos[a], n) - pre[b] - pos[a]);
        dp[i] = min(dp[i], query(1, 1, pos[a]) - pre[b] + pos[a]);
        update(pos[b], mp(dp[b] + pre[b - 1] + pos[b], dp[b] + pre[b - 1] - pos[b]));
    }

    return dp[1];
}

void solve() {
    fillPre();
    buildTree();
    LL ans = findAns();
    printf("%lld\n", ans);
}

int main()
{
	int tc; tc = 1;
    while (tc--) {
        readInput();
        solve();
    }
}


Measured memory_bytes: 14592