// Slower C++ solution:
#include<bits/stdc++.h>

#define F(i,a,b) for(int i=(a);i<=(b);++i)

#define F2(i,a,b) for(int i=(a);i<(b);++i)

#define dF(i,a,b) for(int i=(a);i>=(b);--i)

#define dF2(i,a,b) for(int i=(a);i>(b);--i)

#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)

using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;



int n;

ll a[200001],a1[200001],a2[200001];

int id[200001];

int dat[524289],dat1[524289],dat2[524289];

ll Sum;

int m(ll*arr,int p1,int p2){return arr[p1]<arr[p2]?p1:p2;}

void build(int i,int l,int r){

	if(l==r) {id[l]=i; return;}

	int mid=l+r>>1; build(i<<1,l,mid), build(i<<1|1,mid+1,r);

}

void Mod(int p,ll x){

	a[p]=x; a1[p]=x-p; a2[p]=x+p;

	dat[id[p]]=dat1[id[p]]=dat2[id[p]]=p;

	for(int i=id[p]>>1;i;i>>=1) dat[i]=m(a,dat[i<<1],dat[i<<1|1]), dat1[i]=m(a1,dat1[i<<1],dat1[i<<1|1]), dat2[i]=m(a2,dat2[i<<1],dat2[i<<1|1]);

}

int Qur1(int i,int l,int r,int a,int b){

	if(b<l||r<a) return 0; if(a<=l&&r<=b) return dat1[i];

	int mid=l+r>>1; return m(a1,Qur1(i<<1,l,mid,a,b),Qur1(i<<1|1,mid+1,r,a,b));

}

int Qur2(int i,int l,int r,int a,int b){

	if(b<l||r<a) return 0; if(a<=l&&r<=b) return dat2[i];

	int mid=l+r>>1; return m(a2,Qur2(i<<1,l,mid,a,b),Qur2(i<<1|1,mid+1,r,a,b));

}

int main(){

	memset(a,0x3f,sizeof a);

	memset(a1,0x3f,sizeof a1);

	memset(a2,0x3f,sizeof a2);

	int q,A,B,lst,now;

	scanf("%d%d%d%d%d",&n,&q,&A,&B,&lst);

	build(1,1,n);

	Mod(A,abs(B-lst));

	Mod(B,abs(A-lst));

	F(i,2,q){

		scanf("%d",&now);

		int tmp1=Qur1(1,1,n,1,now),tmp2=Qur2(1,1,n,now,n);

		ll k=min(a1[tmp1]+now,a2[tmp2]-now)-abs(now-lst);

		Sum+=abs(now-lst);

		if(a[lst]>k) Mod(lst,k);

		lst=now;

	}

	printf("%lld",a[dat[1]]+Sum);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.957781001781358x):
#include <bits/stdc++.h>

#define RI register int

#define lc (x << 1)

#define rc (x << 1 | 1)

#define mid ((l + r) >> 1)

typedef long long LL;

#define int LL



using namespace std;



char buf[1000000], *p1 = buf, *p2 = buf;

inline char gc() {

  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);

  return p1 == p2 ? EOF : *(p1++);

}

template <class T> inline void read(T &n) {

  n = 0; RI ch = gc();

  while (ch < '0' || ch > '9') ch = gc();

  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();

}



int const MAXN = 2e5 + 5;

int a[MAXN];

LL min1[MAXN * 4], min2[MAXN * 4], ans[MAXN * 4], add[MAXN * 4];



inline void Update(int x) {

  min1[x] = min(min1[lc], min1[rc]);

  min2[x] = min(min2[lc], min2[rc]);

  ans[x] = min(ans[lc], ans[rc]);

}

inline void Add(int x, int num) {

  min1[x] += num;

  min2[x] += num;

  add[x] += num;

  ans[x] += num;

}

inline void Pushdown(int x) {

  if (add[x]) {

    Add(lc, add[x]);

    Add(rc, add[x]);

    add[x] = 0;

  }

}

void Build(const int x, const int l, const int r, const int &num) {

  if (l == r) return ans[x] = abs(num - l), min1[x] = ans[x] - l, min2[x] = ans[x] + l, void();

  Build(lc, l, mid, num), Build(rc, mid + 1, r, num);

  Update(x);

}

void Modify(const int x, const int l, const int r, const int &pos, const int &num) {

  if (l == r) return ans[x] = min(ans[x], 1ll * num), min1[x] = ans[x] - l, min2[x] = ans[x] + l, void();

  Pushdown(x);

  if (pos <= mid) Modify(lc, l, mid, pos, num);

  else Modify(rc, mid + 1, r, pos, num);

  Update(x);

}

LL Query(const int x, const int l, const int r, const int i, const int j, const int op) {

  if (i <= l && r <= j) return op ? min1[x] : min2[x];

  Pushdown(x);

  LL re = 0x7f7f7f7f7f7f7f7f;

  if (i <= mid) re = min(re, Query(lc, l, mid, i, j, op));

  if (j > mid) re = min(re, Query(rc, mid + 1, r, i, j, op));

  return re;  

}



signed main() {

//  freopen("move.in", "r", stdin);

//  freopen("move.out", "w", stdout);

  int n, Q, A, B;

  read(n), read(Q), read(A), read(B);

  for (RI i = 1; i <= Q; ++i) read(a[i]);

  a[0] = A;

  Build(1, 1, n, B);

  for (RI i = 1; i <= Q; ++i) {

    int Min = std :: min(Query(1, 1, n, 1, a[i], 1) + a[i], Query(1, 1, n, a[i], n, 0) - a[i]);

    Add(1, abs(a[i] - a[i - 1]));

    Modify(1, 1, n, a[i - 1], Min);

  }

  printf("%lld\n", ans[1]);

  return 0;

}