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

struct Idxtree{
    static const int o = 262144;
    ll a[o + o];
    void init(){
        memset(a,0x3f3f3f3f,sizeof(a));
    }
    ll rmq(int s, int e){
        s += o; e += o;
        ll ret = min(a[s], a[e]);
        while(s <= e){
            ret = min({ret, a[s], a[e]});
            ++s >>= 1;
            --e >>= 1;
        }
        return ret;
    }
    void addv(int i, ll v){
        i += o;
        a[i] += v;
        for(;i > 1; i >>= 1){
            a[i >> 1] = min(a[i], a[i^1]);
        }
    }
    void setv(int i, ll v){
        i += o;
        a[i] = v;
        for(; i > 1; i >>= 1){
            a[i >> 1] = min(a[i], a[i^1]);
        }
    }
} Im, Ip;

ll offset;
int n, q, a, b;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    Im.init(); Ip.init();
    cin >> n >> q >> a >> b;
    Im.setv(a, 0ll - a);
    Ip.setv(a, 0ll + a);
    for(int x; q--;){
        cin >> x;
        ll dlt = abs(x - b);
        ll tam = min(x + Im.rmq(1,x), - x + Ip.rmq(x,n)) - dlt;
        Im.setv(b, tam - b);
        Ip.setv(b, tam + b);
        offset += dlt;
        b = x;
    }
    ll ans = LLONG_MAX;
    for(int i = 1; i <= n; i++){
        ans = min(ans, offset + (Im.a[Idxtree::o + i] + Ip.a[Idxtree::o + i])/2);
    }
    cout << ans << '\n';
}