#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
#ifdef DEBUG
template<typename T>
class Vec : public vector<T>{
public:
    Vec(){}
    Vec(int n):vector<T>(n){}
    Vec(int n, T a):vector<T>(n,a){}
    T& operator[](long long n){
        if(n < 0 or n >= this->size())throw out_of_range("Vec");
        return this->at(n);
    }
    const T& operator[](long long n)const{
        if(n < 0 or n >= this->size())throw out_of_range("Vec");
        return this->at(n);
    }
};
#define vector Vec
template<typename T>
ostream &operator<<(ostream &os, set<T> st) {
    for(auto x : st) cerr << x << ' ';
    return os;
}
template<typename T, typename S>
ostream &operator<<(ostream &os, map<T, S> mp) {
    for(auto x : mp) cerr << x << ' ';
    return os;
}
#endif
//Range add, Range min
template<typename T>
struct SegmentTree{
    int n;
    vector<T> node;
    vector<T> lazy;
    const T id = numeric_limits<T>::max() / 2;
    SegmentTree(const vector<T>&d){
        n = 1;
        while(d.size() > n)n *= 2;
        node.resize(2 * n - 1, id);
        lazy.resize(2 * n - 1, T(0));
        for(int i = 0; i < d.size(); i++){
            node[i + n - 1] = d[i];
        }
        for(int i = n - 2; i >= 0; i--){
            node[i] = min(node[2 * i + 1], node[2 * i + 2]);
        }
    }
    SegmentTree(int sz){
        n = 1;
        while(n < sz)n *= 2;
        node.resize(2 * n - 1, id);
        lazy.resize(2 * n - 1, T(0));
    }
    void eval(int k,int l, int r){
        if(lazy[k] != 0){
            node[k] += lazy[k];
            if(r - l > 1){
                lazy[2 * k + 1] += lazy[k];
                lazy[2 * k + 2] += lazy[k];
            }
            lazy[k] = 0;
        }
    }
    void add(const int a,const int b,const T x, int k = 0, int l = 0, int r = -1){
        if(r < 0) r = n;
        eval(k, l, r);
        if(r <= a or b <= l) return;
        if(a <= l and r <= b){
            lazy[k] += x;
            eval(k, l, r);
        }else{
            add(a, b, x, 2 * k + 1, l, (l + r) / 2);
            add(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = min(node[2 * k + 1] , node[2 * k + 2]);
        }
    }
    T query(const int a,const int b,int k = 0, int l = 0, int r = -1){
        if(r < 0) r = n;
        if(r <= a or b <= l){
            return id;
        }
        eval(k, l, r);
        if(a <= l and r <= b){
            return node[k];
        }else{
            T lv = query(a, b, 2 * k + 1, l, (l + r) / 2);
            T rv = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return min(lv, rv);
        }
    }
};
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, q, a, b;
    cin >> n >> q >> a >> b;
    a--; b--;
    vector<int> x(q + 1);
    rep(i,q){
        cin >> x[i + 1];
        x[i + 1]--;
    }
    x[0] = b;
    vector<ll>dummy(n, 1LL<<60);
    dummy[a] = 0;
    rep(i,n)dummy[i] += i;
    SegmentTree<ll> seg1(dummy);
    rep(i,n)dummy[i] -= 2 * i;
    SegmentTree<ll> seg2(dummy);
    rep(i,q){
        ll s = seg1.query(x[i+1],n) - x[i+1];
        ll t = seg2.query(0,x[i+1]) + x[i+1];
        ll k = min(s, t);
        seg1.add(0,n,abs(x[i]-x[i+1]));
        seg2.add(0,n,abs(x[i]-x[i+1]));
        ll temp = seg1.query(x[i],x[i]+1) - x[i];
        if(k < temp){
            seg1.add(x[i],x[i]+1,k - temp);
            seg2.add(x[i],x[i]+1,k - temp);
        }
    }
    ll ans = 1LL<<60;
    rep(i,n){
        ans = min(ans, seg1.query(i,i+1)-i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 19072