#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

template<typename Monoid,typename OperatorMonoid,typename F,typename G,typename H>
class LazySegmentTree {
private:
	int sz,height;
	vec<Monoid> data;
	vec<OperatorMonoid> lazy;
	const F op;
	const G homo;
	const H comp;
  	const Monoid e;
	const OperatorMonoid Oe;
public:
	LazySegmentTree(int n,const F op,const G homo,const H comp,
					const Monoid &e,const OperatorMonoid Oe)
		: op(op),homo(homo),comp(comp),e(e),Oe(Oe) {
		sz = 1;
		height = 0;
		while(sz<=n) sz <<= 1,height++;
		data.assign(2*sz,e);
		lazy.assign(2*sz,Oe);
	}

	void set(int k,const Monoid &x) {
		data[k+sz] = x;
	}

	void build() {
		for(int k=sz-1;k>0;k--) {
			data[k] = op(data[2*k], data[2*k+1]);
		}
	}

	inline void propagate(int k) {
		if(lazy[k]!=Oe) {
			lazy[2*k] = comp(lazy[2*k], lazy[k]);
			lazy[2*k+1] = comp(lazy[2*k+1], lazy[k]);
			data[k] = reflect(k);
			lazy[k] = Oe;
		}
	}

	inline Monoid reflect(int k) {
		return lazy[k] == Oe? data[k]:homo(data[k],lazy[k]);
	}

	inline void recalc(int k) {
		while(k>>=1) data[k] = op(reflect(2*k), reflect(2*k+1));
	}

	inline void thrust(int k) {
		for(int i=height;i>0;i--) propagate(k>>i);
	}

	void update(int a, int b, const OperatorMonoid &x) {
		thrust(a+=sz);
		thrust(b+=sz-1);
		for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
			if(l&1) lazy[l] = comp(lazy[l],x),++l;
			if(r&1) --r, lazy[r] = comp(lazy[r],x);
		}
		recalc(a);
		recalc(b);
	}

	Monoid query(int a, int b) {
		thrust(a+=sz);
		thrust(b+=sz-1);
		Monoid L = e, R = e;
		for(int l=a, r=b+1;l<r;l>>= 1,r>>=1) {
			if(l&1) L = op(L,reflect(l++));
			if(r&1) R = op(reflect(--r),R);
		}
		return op(L,R);
	}

	Monoid operator[](const int &k) {
		return query(k,k+1);
	}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q,A,B;
    cin >> N >> Q >> A >> B;
    A--; B--;
    vec<ll> q(Q+1);
    for(int i=1;i<=Q;i++){
        cin >> q[i];
        q[i]--;
    }
    ll a = 0;
    ll d = 0;
    if(A==B){
        B = q[1];
        d = 1;
        a += abs(q[1]-A);
    }
    ll inf = 1e18;
    auto mymin = [](ll a,ll b){return min(a,b);};
    auto add = [](ll a,ll b){return a+b;};
    LazySegmentTree<ll,ll,decltype(mymin),decltype(add),decltype(add)>
    segL(N,mymin,add,add,2*inf,0),segR(N,mymin,add,add,2*inf,0);
    for(int i=0;i<N;i++){
        segL.set(i,inf);
        segR.set(i,inf);
    }
    segL.set(B,-B);
    segR.set(B,B);
    segL.set(A,-A);
    segR.set(A,A);
    segL.build(); segR.build();
    q[0] = A;
    for(int i=1+d;i<=Q;i++){
        ll mi = inf;
        if(q[i-1]<q[i]){
            mi = min(segL.query(0,q[i-1])+q[i],segL.query(q[i-1]+1,q[i])+q[i]);
            mi = min(mi,segR.query(q[i],N)-q[i]);
        }else{
            mi = min(segR.query(q[i],q[i-1])-q[i],segR.query(q[i-1]+1,N)-q[i]);
            mi = min(mi,segL.query(0,q[i]+1)+q[i]);
        }

        ll now = segL[q[i-1]];
        segL.update(q[i-1],q[i-1]+1,-now+mi-q[i-1]);
        now = segR[q[i-1]];
        segR.update(q[i-1],q[i-1]+1,-now+mi+q[i-1]);

        segL.update(0,q[i-1],abs(q[i]-q[i-1]));
        segL.update(q[i-1]+1,N,abs(q[i]-q[i-1]));
        segR.update(0,q[i-1],abs(q[i]-q[i-1]));
        segR.update(q[i-1]+1,N,abs(q[i]-q[i-1]));
//        for(int i=0;i<N;i++) cerr << segL[i]+i << (i!=N-1? " ":"\n");
//        for(int i=0;i<N;i++) cerr << segR[i]+i << (i!=N-1? " ":"\n");
    }

    ll ans = inf;
    for(ll i=0;i<N;i++) ans = min({ans,segL[i]+i,segR[i]-i});
    cout << ans+a << endl;
}

Measured memory_bytes: 20224