#include <bits/stdc++.h>
#define INF 12345678901234ll
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int N, Q, A, B;
LL D[202020], Sum, ans;

struct SegTree{
    LL Min[808080];

    void update(int id, int s, int e, int t, LL v){
        if (e < t || t < s) return;
        if (s == e){
            Min[id] = v;
            return;
        }
        int mid = (s+e)/2;
        update(id*2, s, mid, t, v);
        update(id*2+1, mid+1, e, t, v);
        Min[id] = min(Min[id*2], Min[id*2+1]);
    }

    LL query(int id, int s, int e, int ts, int te){
        if (e < ts || te < s) return INF;
        if (ts <= s && e <= te) return Min[id];
        int mid = (s+e)/2;
        return min(query(id*2, s, mid, ts, te), query(id*2+1, mid+1, e, ts, te));
    }
} Pj, Mj;

int main(){
    scanf("%d %d %d %d", &N, &Q, &A, &B);
    fill(D, D+N+1, INF);
    D[B] = 0;
    for (int i=1; i<=N; i++){
        Pj.update(1, 1, N, i, D[i]+i);
        Mj.update(1, 1, N, i, D[i]-i);
    }
    while (Q--){
        scanf("%d", &B);
        LL k = min(Mj.query(1, 1, N, 1, B)+B, Pj.query(1, 1, N, B, N)-B) + Sum;
        Sum += abs(A-B);
        if (D[A]+Sum > k) D[A] = k-Sum;
        Mj.update(1, 1, N, A, D[A]-A);
        Pj.update(1, 1, N, A, D[A]+A);
        A = B;
    }
    ans = INF;
    for (int i=1; i<=N; i++) ans = min(ans, D[i]+Sum);
    printf("%lld\n", ans);
    return 0;
}
