#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

P xs[200100];
int order[200100];

struct SegmentTree{
    SegmentTree(int n){
        size = 1;
        while(size < n){
            size *= 2;
        }
    }
    void propagate(int k){
        if(data2[k] != 0){
            data[k] = min(data[k] + data2[k], D);
            if(k < size){
                data2[k*2] += data2[k];
                data2[k*2+1] += data2[k];
            }
            data2[k] = 0;
        }
    }
    void update(ll x, int l, int r){
        _update(1, 0, size, x, l, r);
    }
    inline void _update(int k, int a, int b, ll x, int l, int r){
        propagate(k);

        if(b <= l || r <= a){return;}
        if(l <= a && b <= r){
            data2[k] = x;
            propagate(k);
        }else{
            int mid = (a + b) / 2;
            _update(k * 2, a, mid, x, l, r);
            _update(k * 2 + 1, mid, b, x, l, r);
            data[k] = min(data[k*2], data[k*2+1]);
        }
    }
    ll minimum(int l, int r){
        return _minimum(1, 0, size, l, r);
    }
    inline ll _minimum(int k, int a, int b, int l, int r){
        propagate(k);

        if(b <= l || r <= a){return D;}
        if(l <= a && b <= r){return data[k];}
        int mid = (a + b) / 2;
        ll vl = _minimum(k * 2, a, mid, l, r),
            vr = _minimum(k * 2 + 1, mid, b, l, r);
        return min(vl, vr);
    }
    
    int size;
    ll data[800400], data2[800400];
    const ll D = numeric_limits<ll>::max() / 2;
};

SegmentTree seg_p(200100), seg_n(200100);

void helper(ll v, int x, SegmentTree &seg){
    ll w = seg.minimum(x, x + 1);
    seg.update(v - w, x, x + 1);
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    seg_p.update(seg_p.D, 0, 200100);
    seg_n.update(seg_p.D, 0, 200100);
    
    int N, Q, A, B;
    std::cin >> N >> Q >> A >> B;

    xs[1] = std::make_tuple(A, 1);
    xs[2] = std::make_tuple(B, 2);
    
    for(int i=3;i<Q+3;++i){
        int x;
        std::cin >> x;

        xs[i] = std::make_tuple(x, i);
    }

    sort(xs+1, xs+Q+3);

    for(int i=1;i<Q+3;++i){
        order[snd(xs[i])] = i;
    }

    helper(A, order[1], seg_p);
    helper(-A, order[1], seg_n);
    
    for(int i=3;i<Q+3;++i){
        int x = fst(xs[order[i]]), y = fst(xs[order[i-1]]);
        ll v = min(seg_n.minimum(1, order[i]) + x,
                   seg_p.minimum(order[i] + 1, Q + 3) - x);

        helper(v + y, order[i-1], seg_p);
        helper(v - y, order[i-1], seg_n);
        
        int d = abs(fst(xs[order[i]]) - fst(xs[order[i-1]]));
        seg_p.update(d, 1, order[i-1]);
        seg_p.update(d, order[i-1] + 1, Q + 3);
        seg_n.update(d, 1, order[i-1]);
        seg_n.update(d, order[i-1] + 1, Q + 3);
    }

    ll res = seg_p.D;
    for(int i=1;i<Q+2;++i){
        res = min(res, seg_p.minimum(order[i], order[i] + 1) - fst(xs[order[i]]));
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 19072