//#define DEB1 //output check function
//#define DEB2 //same output, input from input.txt

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define IN(a, x, b) (a<=x && x<b)
#define RNG(a) a.begin(),a.end()
#define pb push_back

using namespace std;

using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


#ifdef DEB1
#define DPRINT(x) cout<< #x << "=" << (x) << endl; // print at debug mode
#else
#define DPRINT(x) ;
#endif
#ifdef DEB1
#define DCHECK(x) cout<< "debug check" << #x << endl;
#else
#define DCHECK(x) ;
#endif
 


/*
constant values
*/

//const int dx[] = {1,0,-1,0};
//const int dy[] = {0,1,0,-1};
const int MN = 1<<18; // 1001001 1e6

const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9
ll SegT[2][MN*2+10];


// ----------------------------------------------
//Functions for segment tree
//set SegT[id][N] use N=id segment trees

//return the min value in[a,b) of array SegT[id]
ll query(int a,int b,int id,int k=0,int l=0,int r=MN){

	if(r<=a || b<=l) return INF; //Request don't match the Tree
	if(a<=l && r<=b) return SegT[id][k]; // Request overlap the Tree -> return minimum (Tree[0])

    //Request partially overlap the Tree -> go to smaller Tree
	ll vl=query(a,b,id,k*2+1,l,(l+r)/2); //left node
	ll vr=query(a,b,id,k*2+2,(l+r)/2,r); //right node
	return min(vl,vr);

    //what happens if [b] is minimum
}

//update k index of Segtree with a
void update(int id,int k,ll a){
	k+=MN-1;
	SegT[id][k]=a;
	while(k>0){
        DPRINT(k)
		k=(k-1)/2;
		SegT[id][k]=min(SegT[id][k*2+1],SegT[id][k*2+2]);

	}
	return;
}

// ----------------------------------------------



// Main program
void solve(){
    int N,Q,A,B,x;
    cin >> N >> Q >> A >> B;

    //initiate segT
    REP(i,2*MN+1) REP(id,2) SegT[id][i]=INF;

    // use A as initial x
    update(0,B,-B);
    update(1,B,B);
    DPRINT(B)

    ll sum = 0;
    ll cost = 0;
    int x_pre = A;

    REP(i,Q){
        cin >> x;

        //move Other_i -> x
        DPRINT(SegT[0][1])


        ll leftmin = query(1,x,0) + x ;
        ll rightmin = query(x,N+1,1) - x ;
        DPRINT(leftmin)
        DPRINT(rightmin)

        int diff = abs(x - x_pre);
        DPRINT(diff)
        sum+= diff;


        cost = min(leftmin,rightmin) - diff ;

        DPRINT(cost)
        
        update(0,x_pre,cost - x_pre);
        update(1,x_pre,cost + x_pre);
        
        x_pre = x;
        
    }
    ll ans;
    ans = INF;
    DPRINT(SegT[0][B+MN-1])

    REP(i,N+2){
        chmin(ans, SegT[0][i+MN-1] + i );
        DPRINT(ans)
    }
    DPRINT(ans)
    ans += sum;


    cout << ans << endl;

}



// ----------------------------------------------

int main() {

#ifdef DEB2
    cout << "DEBUG MODE"  << endl;
	ifstream in("input.txt"); //for debug
	cin.rdbuf(in.rdbuf()); //for debug
#endif

	int T=1; 

	for (int i = 0; i < T; ++i) {
		solve();
	}
}



Measured memory_bytes: 8448