#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

template<typename T> class segtree {
private:
    int n,sz,h;
    vector<T> node, lazy;
    void eval(int k) {
        if(lazy[k]){
            node[k] += lazy[k];
            if(k < n) {
                lazy[k*2] += lazy[k], lazy[k*2+1] += lazy[k];
            }
            lazy[k] = 0;
        }
    }

public:
    segtree(const vector<T>& v) : n(1), sz((int)v.size()), h(0) {
        while(n < sz) n *= 2, h++;
        node.resize(2*n, numeric_limits<T>::max());
        lazy.resize(2*n, 0);
        for(int i = 0; i < sz; i++) node[i+n] = v[i];
        for(int i = n-1; i >= 1; i--) node[i] = min(node[2*i], node[2*i+1]);
    }
    void range(int a, int b, T x, int k=1, int l=0, int r=-1){
        if(r < 0) r = n;
        eval(k);
        if(b <= l || r <= a){
            return;
        }
        if(a <= l && r <= b){
            lazy[k] += x;
            eval(k);
        }else{
            range(a, b, x, 2*k, l, (l+r)/2);
            range(a, b, x, 2*k+1, (l+r)/2, r);
            node[k] = min(node[2*k], node[2*k+1]);
        }
    }
    T query(int a, int b) {
        a += n, b += n - 1;
        for(int i = h; i > 0; i--) eval(a >> i), eval(b >> i);
        b++;
        T res1 = numeric_limits<T>::max(), res2 = numeric_limits<T>::max();
        while(a < b) {
            if(a & 1) eval(a), res1 = min(res1, node[a++]);
            if(b & 1) eval(--b), res2 = min(res2, node[b]);
            a >>= 1, b >>= 1;
        }
        return min(res1, res2);
    }
    void print(){for(int i = 0; i < sz; i++) cout<<query(i,i+1)<< " ";cout<<endl;}
};

int main(){
    int n,q,a,b;
    cin >> n >> q >> a >> b;
    a--;b--;
    vector<int> p(q+1);
    rep(i,q){
        cin >> p[i+1];
        p[i+1]--;
    }
    p[0] = b;
    vector<ll> v(n,1LL<<40);
    segtree<ll> sg(v),sg2(v);
    ll k = sg.query(a,a+1);
    sg.range(a,a+1,-k);
    sg.range(a,a+1,-a);
    sg2.range(a,a+1,-k);
    sg2.range(a,a+1,a);
    rep(i,q){
        ll x = p[i+1];
        ll s = abs(p[i+1]-p[i]);
        ll mi = sg.query(0,x)+x;
        mi = min(mi,sg2.query(x,n)-x);
        ll c;
        c = sg.query(p[i],p[i]+1);
        sg.range(p[i],p[i]+1,-c);
        sg.range(p[i],p[i]+1,mi-p[i]);
        
        c = sg2.query(p[i],p[i]+1);
        sg2.range(p[i],p[i]+1,-c);
        sg2.range(p[i],p[i]+1,mi+p[i]);

        sg.range(0,p[i],s);
        sg.range(p[i]+1,n,s);
        sg2.range(0,p[i],s);
        sg2.range(p[i]+1,n,s);
        //sg.print();
        //sg2.print();
    }
    ll res = 1LL<<60;
    rep(i,n){
        res = min(res,sg.query(i,i+1)+i);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 19072