#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const int N=1e6;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
LL f[N],pre[N],suf[N],ans=1LL<<60;
#define lc (i<<1)
#define rc (lc|1)
inline void build(int i,int l,int r) {
	if (l==r) pre[i]=f[l]-l,suf[i]=f[r]+r;
	else {
		int mid=(l+r)>>1;
		build(lc,l,mid);
		build(rc,mid+1,r);
		pre[i]=min(pre[lc],pre[rc]);
		suf[i]=min(suf[lc],suf[rc]);
	}
}
inline LL Q1(int i,int l,int r,int R) {
	if (r<=R) return pre[i];
	int mid=(l+r)>>1;
	return R<=mid?Q1(lc,l,mid,R):min(pre[lc],Q1(rc,mid+1,r,R));
}
inline LL Q2(int i,int l,int r,int L) {
	if (L<=l) return suf[i];
	int mid=(l+r)>>1;
	return mid<L?Q2(rc,mid+1,r,L):min(suf[rc],Q2(lc,l,mid,L));
}
inline void modify(int i,int l,int r,int k,LL w) {
	if (l==r) pre[i]=w-l,suf[i]=w+r;
	else {
		int mid=(l+r)>>1;
		k<=mid?modify(lc,l,mid,k,w):modify(rc,mid+1,r,k,w);
		pre[i]=min(pre[lc],pre[rc]);
		suf[i]=min(suf[lc],suf[rc]);
	}
}
inline void solve(int i,int l,int r) {
	if (l==r) ans=min(ans,pre[i]+l);
	else {
		int mid=(l+r)>>1;
		solve(lc,l,mid);
		solve(rc,mid+1,r);
	}
}
int main()
{
	int n=gi(),Q=gi(),A=gi(),last=gi(),i,x;LL tag=0,p;
	for (i=1;i<=n;i++) f[i]=i==A?0:1LL<<60;
	build(1,1,n);
	while (Q--) {
		x=gi();
		p=min(x+Q1(1,1,n,x),Q2(1,1,n,x)-x);
		tag+=abs(x-last);
		modify(1,1,n,last,p-abs(x-last));
		last=x;
	}
	solve(1,1,n);
	printf("%lld\n",ans+tag);
	return 0;
}
