#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll a[200001];

struct node
{
	ll lazy;
	ll ans;
};

node st[2][3][800001];
int N,n; ll x,y; 

void combine(int i1, int i2, int id)
{
	st[i1][i2][id].ans=min(st[i1][i2][id*2].ans,st[i1][i2][id*2+1].ans);
}

void build(int i1, int i2, int id, int l, int r)
{
	if(r-l<2)
	{
		ll val = ll(1e12);
		if(i1==0&&l==x) val=abs(a[1]-y);
		else if(i1==1&&l==y) val=abs(a[1]-x);
		if(i2==1) val+=(N-1-l);
		if(i2==2) val+=l;
		st[i1][i2][id].ans=val;
		st[i1][i2][id].lazy=0;
		return ;
	}
	int mid=(l+r)>>1;
	build(i1,i2,id*2,l,mid);
	build(i1,i2,id*2+1,mid,r);
	combine(i1,i2,id);
}

void push(int i1, int i2, int id, int l, int r)
{
	if(st[i1][i2][id].lazy!=0)
	{
		st[i1][i2][id].ans+=st[i1][i2][id].lazy;
		if(r-l>=2)
		{
			st[i1][i2][id*2].lazy+=st[i1][i2][id].lazy;
			st[i1][i2][id*2+1].lazy+=st[i1][i2][id].lazy;
		}
		st[i1][i2][id].lazy=0;
	}
}

void update(int i1, int i2, int id, int l, int r, int ql, int qr, ll val)
{
	push(i1,i2,id,l,r);
	if(ql>=r||l>=qr) return ;
	if(ql<=l&&r<=qr)
	{
		//cerr<<l<<' '<<r<<' '<<ql<<' '<<qr<<'\n';
		st[i1][i2][id].lazy+=val;
		push(i1,i2,id,l,r);
		//cerr<<id<<' '<<l<<' '<<r<<' '<<st[i1][i2][id].ans<<'\n';
		return ;
	}
	int mid=(l+r)>>1;
	update(i1,i2,id*2,l,mid,ql,qr,val);
	update(i1,i2,id*2+1,mid,r,ql,qr,val);
	combine(i1,i2,id);
	//cerr<<id<<' '<<l<<' '<<r<<' '<<st[i1][i2][id].ans<<'\n';
}

ll query(int i1, int i2, int id, int l, int r, int ql, int qr)
{
	push(i1,i2,id,l,r);
	if(ql>=r||l>=qr) return ll(5e18);
	if(ql<=l&&r<=qr)
	{
		return st[i1][i2][id].ans;
	}
	int mid=(l+r)>>1;
	return min(query(i1,i2,id*2,l,mid,ql,qr),query(i1,i2,id*2+1,mid,r,ql,qr));
}

ll queryabs(int i1, ll pos)
{
	ll v1 = query(i1,1,1,0,N,0,pos+1)-(N-1-pos);
	ll v2 = query(i1,2,1,0,N,pos,N)-pos;
	return min(v1,v2);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>N>>n>>x>>y;
	x--; y--;
	for(int i=1;i<=n;i++) 
	{
		cin>>a[i];
		a[i]--;
	}
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<3;j++)
		{
			build(i,j,1,0,N);
		}
	}
	for(int i=2;i<=n;i++)
	{
		ll cur0 = queryabs(1,a[i]);
		ll cur1 = queryabs(0,a[i]);
		for(int j=0;j<2;j++)
		{
			for(int k=0;k<3;k++)
			{
				update(j,k,1,0,N,0,N,abs(a[i]-a[i-1]));
			}
		}
		ll z[3]; ll diff[3];
		for(int j=0;j<3;j++) z[j] = query(0,j,1,0,N,a[i-1],a[i-1]+1);
		diff[1]=N-1-a[i-1];
		diff[0]=0;
		diff[2]=a[i-1];
		if(cur0<z[0])
		{
			for(int k=0;k<3;k++)
			{
				update(0,k,1,0,N,a[i-1],a[i-1]+1,cur0+diff[k]-z[k]);
			}
		}
		{
			ll ans = query(0,0,1,0,N,0,N);
			ll ans2 = query(1,0,1,0,N,0,N);
			//cerr<<i<<' '<<ans<<' '<<ans2<<'\n';
		}
		////cerr<<query(0,0,1,0,N,a[i-1],a[i-1]+1)<<'\n';
		for(int j=0;j<3;j++) z[j] = query(1,j,1,0,N,a[i-1],a[i-1]+1);
		if(cur1<z[0])
		{
			for(int k=0;k<3;k++)
			{
				//cerr<<query(1,0,1,0,N,0,N)<<'\n';
				//cerr<<query(1,k,1,0,N,a[i-1],a[i-1]+1)+cur1+diff[k]-z[k]<<'\n';
				update(1,k,1,0,N,a[i-1],a[i-1]+1,cur1+diff[k]-z[k]);
				//cerr<<query(1,0,1,0,N,0,N)<<'\n';
				//cerr<<query(1,k,1,0,N,a[i-1],a[i-1]+1)<<'\n';
			}
		}
		//cerr<<a[i-1]<<'\n';
		{
			ll ans = query(0,0,1,0,N,0,N);
			ll ans2 = query(1,0,1,0,N,0,N);
			//cerr<<i<<' '<<ans<<' '<<ans2<<'\n';
		}
		////cerr<<query(1,0,1,0,N,a[i-1],a[i-1]+1)<<'\n';
		ll ans = query(0,0,1,0,N,0,N);
		ll ans2 = query(1,0,1,0,N,0,N);
		//cerr<<i<<' '<<ans<<' '<<ans2<<'\n';
	}
	ll ans = query(0,0,1,0,N,0,N);
	ll ans2 = query(1,0,1,0,N,0,N);
	cout<<min(ans,ans2)<<'\n';
}


Measured memory_bytes: 64512