#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 1e17;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
// priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
// #define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
 
ll mod = 998244353;
//ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/

struct LazySegmentTree {
private:
    int n;
    ll accsum;
    vector<ll> size;
    vector<ll> node;
    vector<ll> nodel, noder;
 
public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        accsum = 0;
        n = 1; while(n < sz) n *= 2;
        size.resize(2*n-1, 0);
        node.resize(2*n-1);
        nodel.resize(2*n-1, 0);
        noder.resize(2*n-1, 0);
 
        for(int i=0; i<sz; i++) {
            node[i+n-1] = v[i];
            size[i+n-1] = 1;
        }
        for(int i=n-2; i>=0; i--) {
            size[i] = size[i*2+1] * 2;
        }

        for(int i=0; i<sz; i++) {
            nodel[i+n-1] = i;
            noder[i+n-1] = i;
        }
        for(int i=n-2; i>=0; i--) {
            ll valuel = node[nodel[i*2+1]+n-1];
            ll valuer = node[nodel[i*2+2]+n-1];
            ll length = size[i*2+1];
            if(valuel < length + valuer){
                nodel[i] = nodel[i*2+1];
            }else{
                nodel[i] = nodel[i*2+2];
            }
        }
        for(int i=n-2; i>=0; i--) {
            ll valuel = node[noder[i*2+1]+n-1];
            ll valuer = node[noder[i*2+2]+n-1];
            ll length = size[i*2+1];
            if(valuel + length < valuer){
                noder[i] = noder[i*2+1];
            }else{
                noder[i] = noder[i*2+2];
            }
        }
    }

    ll getvalue(ll idx){
        // idx番目の値を取得
        return node[idx + n - 1];
    }

    void update(ll idx, ll value){
        // 小さい方に更新しました
        ll nodeidx = idx + n - 1;
        node[nodeidx] = min(node[nodeidx], value);
        while(nodeidx > 0){
            nodeidx = (nodeidx - 1) / 2;

            ll before = node[nodel[nodeidx]+n-1] + nodel[nodeidx];
            ll after = value + idx;

            if(after < before){
                nodel[nodeidx] = idx;
            }

            before = node[noder[nodeidx]+n-1] - noder[nodeidx];
            after = value - idx;

            if(after < before){
                noder[nodeidx] = idx;
            }
        }
    }

    void addall(ll value){
        accsum += value;
        return;
    }

    ll query(ll idx, int k=0, int l=0, int r=-1){
        int a = 0, b = n - 2;
        if(r < 0)r = n;
        if(r <= a || b <= l) return INF;
        if(a <= l && r <= b) {
            if(idx <= l){
                return node[nodel[k]+n-1] + abs(nodel[k] - idx);
            }else if(idx >= r){
                return node[noder[k]+n-1] + abs(noder[k] - idx);
            }
        }
        ll vl = query(idx, 2*k+1, l, (l+r)/2);
        ll vr = query(idx, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

LazySegmentTree seg(vector<ll>(200010, INF));


ll n,m,num,sum,a,b,c,d,e,h,r,l,q;
ll k;
ll query[500005];


void check(){
    return;
    for(ll i=1;i<=n;i++){
        ll tmp = seg.getvalue(i);
        if(tmp >= INF){
            pe("x");
        }else{
            pe(tmp);
        }
    }
    el;
}

int main(){
    cin >> n >> q >> a >> b;
    for(ll i=0;i<q;i++){
        cin >> query[i];
    }
    seg.update(a, abs(query[0] - b));
    seg.update(b, abs(query[0] - a));
    ll accsum = 0;
    for(ll i=1;i<q;i++){
        check();
        ll point = query[i];
        ll dif = abs(query[i-1] - point);
        ll res = seg.query(point);
        ll before = query[i-1];
        accsum += dif;
        seg.update(before, res - dif);
    }
    check();
    ll ans = INF;
    for(ll i=1;i<=n;i++){
        ans = min(ans, seg.getvalue(i) + accsum);
    }
    p(ans);
    return 0;
}


















Measured memory_bytes: 20196