#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=2e5,MAX_SQRT_N=448;
int N,Q,A,B;
const ll INF=1e16;
ll dp[MAX_N],bsm[MAX_SQRT_N+1],bqu[MAX_SQRT_N+1][2];
int sq;
int main(){
	cin>>N>>Q>>A>>B;
	sq=1;
	while(sq*sq<N){
		sq++;
	}
	REP(i,N){
		dp[i]=INF;
	}
	int x;
	cin>>x;
	A--;
	B--;
	x--;
	dp[A]=abs(B-x);
	dp[B]=abs(A-x);
	REP(i,(N+sq-1)/sq){
		bqu[i][0]=INF+1;
		REP(j,sq){
			if (i*sq+j>=N){
				break;
			}
			bqu[i][0]=min(bqu[i][0],dp[i*sq+j]+j+1);
		}
		bqu[i][1]=INF+1;
		int c=1;
		for(int j=sq-1;j>=0;j--){
			if (i*sq+j>=N){
				continue;
			}
			bqu[i][1]=min(bqu[i][1],dp[i*sq+j]+c);
			c++;
		}
	}
	int prex=x;
	REP(q,Q-1){
		cin>>x;
		x--;
		ll tem=INF;
		REP(i,(N+sq-1)/sq){
			if (i*sq<=x && x<(i+1)*sq){
				REP(j,sq){
					if (i*sq+j>=N){
						break;
					}
					tem=min(tem,dp[i*sq+j]+abs(i*sq+j-x)+bsm[i]);
				}
			}else if ((i+1)*sq<=x){
				tem=min(tem,bqu[i][1]+x-(i+1)*sq+bsm[i]);
			}else{
				tem=min(tem,bqu[i][0]+i*sq-x-1+bsm[i]);
			}
		}
		REP(i,(N+sq-1)/sq){
			if (i*sq<=prex && prex<(i+1)*sq){
				REP(j,sq){
					if (i*sq+j>=N){
						break;
					}
					dp[i*sq+j]+=bsm[i]+abs(x-prex);
				}
				bsm[i]=0;
			}else{
				bsm[i]+=abs(x-prex);
			}
		}
		dp[prex]=min(dp[prex],tem);
		bqu[prex/sq][0]=INF+1;
		REP(j,sq){
			if (prex/sq*sq+j>=N){
				break;
			}
			bqu[prex/sq][0]=min(bqu[prex/sq][0],dp[prex/sq*sq+j]+j+1);
		}
		bqu[prex/sq][1]=INF+1;
		int c=1;
		for(int j=sq-1;j>=0;j--){
			if (prex/sq*sq+j>=N){
				continue;
			}
			bqu[prex/sq][1]=min(bqu[prex/sq][1],dp[prex/sq*sq+j]+c);
			c++;
		}
		prex=x;
	}
	ll ans=INF;
	REP(i,N){
		ans=min(ans,dp[i]+bsm[i/sq]);
	}
	cout<<ans<<endl;	
	return 0;
}