#include <bits/stdc++.h>
using namespace std;
#define int long long 
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}

#define cerr cout

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MP make_pair
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl


// // int mod=1e9+7;
// inline int mul(int a,int b){return (a*1ll*b)%mod;}
// inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
// inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
// inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
// inline int inv(int a){return power(a,mod-2);}
// inline void modadd(int &a,int &b){a+=b;if(a>=mod)a-=mod;} 

const int maxn=1e6+100;
const ll INF=1e18;
ll x[maxn];
ll seg[maxn][2],laz[maxn][2];

ll mul[2]={-1,1};

ll N;
#define M ((s+e)/2)
void build(int node,int s,int e){
    For(j,2){
        seg[node][j]=INF;
        laz[node][j]=0;
    }
    if (s!=e){
        build(2*node,s,M);
        build(2*node+1,M+1,e);
    }
}

void rmv(int node,int s,int e,int tp){
    if (laz[node][tp]==0) return;
    seg[node][tp]+=laz[node][tp];
    if (s!=e){
        laz[2*node][tp]+=laz[node][tp];
        laz[2*node+1][tp]+=laz[node][tp];
    }
    laz[node][tp]=0;
}

void update1(int node,int s,int e,int tp,int l,int val){
    rmv(node,s,e,tp);
    if (l>e || l<s) return;
    if (s==e){
        
        seg[node][tp]=min(seg[node][tp],mul[tp]*s+val);
        assert(laz[node][tp]==0);
        return;
    }
    update1(2*node,s,M,tp,l,val);
    update1(2*node+1,M+1,e,tp,l,val);
    seg[node][tp]=min(seg[2*node][tp],seg[2*node+1][tp]);
    
}

void update1(int l,int val){
    update1(1,1,N,0,l,val);
    update1(1,1,N,1,l,val);
}
void update2(int node,int s,int e,int tp,int l,int r,int val){
    rmv(node,s,e,tp);
    if (e<l || s>r) return;
    if (l<=s && e<=r){
        laz[node][tp]+=val;
        rmv(node,s,e,tp);
        return;
    }
    update2(2*node,s,M,tp,l,r,val);
    update2(2*node+1,M+1,e,tp,l,r,val);
    seg[node][tp]=min(seg[2*node][tp],seg[2*node+1][tp]);
}
void update2(int l,int r,int val){
    update2(1,1,N,0,l,r,val);
    update2(1,1,N,1,l,r,val);
}
ll query(int node,int s,int e,int tp,int l,int r){
    rmv(node,s,e,tp);
    if (e<l || s>r) return INF;
    if (l<=s && e<=r) return seg[node][tp];
    return min(query(2*node,s,M,tp,l,r),query(2*node+1,M+1,e,tp,l,r));
}

// void print(int n){
//     Rep(i,n){
//         d0(query(1,1,n,0,i,i)+i);
//     }
//     d1("");
// }

signed main(){
	fio; cout<<fixed<<setprecision(25);
	#ifndef ONLINE_JUDGE 
		freopen("error.txt","w",stderr);
	#endif 
	
	ll n,q,a,b;
	cin>>n>>q>>a>>b;
	N=n;
	Rep(i,q) cin>>x[i];
	build(1,1,n);
	update1(a,0);
	ll cu=b;
	Rep(i,q){
	    
	    ll v=query(1,1,n,0,1,x[i])+x[i];
	    ll w=query(1,1,n,1,x[i],n)-x[i];
	    ll B=cu,C=x[i];
	    ll k=min(v,w);
	   // trace(i,v,w,B,C,x[i],k);
	    update2(1,n,abs(cu-x[i]));
	    update1(cu,k);
	   // print(n);
	    cu=x[i];
	}
	ll ans=INF;
	Rep(i,n){
	    ans=min(ans,query(1,1,n,0,i,i)+i);
	}
	
	
	d1(ans);
}

Measured memory_bytes: 24832