#include<bits/stdc++.h>
using namespace std;
#define y1 A2Dalek
#define y0 Cyberman
#define yn RoseTyler
#define j1 JackHarkness
#define fs first
#define sd second
const int N=2e5;
const long long oo=1e16+5;
int du[]={-1,0,0,1};
int dv[]={0,-1,1,0};
const long long mod=1e9+7;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
long long sqr(long long x) {return x*x;}
int getbit(int state, int i) {return ((state>>i)&1);}

int n,nq,A,B,q[N+5];
long long res=oo;
struct IT
{
    long long f[4*N+5];
    long long lz[4*N+5];
    long long a[N+5];
    void build(int id, int l, int r)
    {
        if (l>r) return;
        if (l==r) {f[id]=a[l]; return;}
        int mid=(l+r)/2;
        build(id*2,l,mid); build(id*2+1,mid+1,r);
        f[id]=min(f[id*2],f[id*2+1]);
    }
    void down(int id)
    {
        long long val=lz[id]; lz[id]=0;
        f[id*2]+=val; f[id*2+1]+=val;
        lz[id*2]+=val; lz[id*2+1]+=val;
    }
    void update(int id, int l, int r, int u, long long val)
    {
        if (l>u || r<u || l>r) return;
        if (l==r)
        {
            f[id]=min(f[id],val);
            return;
        }
        int mid=(l+r)/2;
        down(id);
        update(id*2,l,mid,u,val); update(id*2+1,mid+1,r,u,val);
        f[id]=min(f[id*2],f[id*2+1]);
    }
    long long get(int id, int l, int r, int u, int v)
    {
        if (l>r || l>v || r<u) return oo;
        if (u<=l && r<=v) return f[id];
        int mid=(l+r)/2;
        down(id);
        return min(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v));
    }
} tru,cong;
int main()
{
	//freopen("Many Moves.inp","r",stdin);
	//freopen("Many Moves.out","w",stdout);
	ios_base::sync_with_stdio(false);
    cin>>n>>nq;
    cin>>A>>B;
    for (int i=1;i<=n;i++)
    {
        tru.a[i]=abs(B-i)-i;
        cong.a[i]=abs(B-i)+i;
    }
    tru.build(1,1,n); cong.build(1,1,n);
    q[0]=A;
    for (int i=1;i<=nq;i++)
    {
        cin>>q[i];
        long long val=abs(q[i]-q[i-1]);
        long long now=min(tru.get(1,1,n,1,q[i])+q[i], cong.get(1,1,n,q[i],n)-q[i]);
        tru.f[1]+=val; cong.f[1]+=val;
        tru.lz[1]+=val; cong.lz[1]+=val;
        tru.update(1,1,n,q[i-1],now-q[i-1]);
        cong.update(1,1,n,q[i-1],now+q[i-1]);
    }
    for (int i=1;i<=n;i++)
    {
        res=min(res,tru.get(1,1,n,i,i)+i);
    }
    cout<<res;
	return 0;
}

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cctype>
#include <iostream>
#include <cstring>
#include <algorithm>
#define R register
#define IN inline
#define W while
#define ls (now << 1)
#define rs ((now << 1) | 1)
#define MX 200500
#define gc getchar()
#define ll long long
template <class T>
IN void in(T &x)
{
	x = 0; R char c = gc;
	for (; !isdigit(c); c = gc);
	for (;  isdigit(c); c = gc)
	x = (x << 1) + (x << 3) + c - 48;
}
template <class T> IN T max(T a, T b) {return a > b ? a : b;}
template <class T> IN T min(T a, T b) {return a < b ? a : b;}
template <class T> IN T abs(T a) {return a > 0 ? a : -a;}
int n, q;
struct Node
{
	ll val[3], tag;
	Node(){std::memset(val, 63, sizeof(val));}
}tree[MX << 2];
IN void pushup(R int now)
{
	tree[now].val[0] = min(tree[ls].val[0], tree[rs].val[0]);
	tree[now].val[1] = min(tree[ls].val[1], tree[rs].val[1]);
	tree[now].val[2] = min(tree[ls].val[2], tree[rs].val[2]);
}
IN void pushdown(R int now)
{
	if (tree[now].tag)
	{
		tree[ls].val[0] += tree[now].tag;
		tree[ls].val[1] += tree[now].tag;
		tree[ls].val[2] += tree[now].tag;
		tree[ls].tag	+= tree[now].tag;
		tree[rs].val[0] += tree[now].tag;
		tree[rs].val[1] += tree[now].tag;
		tree[rs].val[2] += tree[now].tag;
		tree[rs].tag	+= tree[now].tag;
		tree[now].tag = 0;
	}
}
void modify(R int now, R int lef, R int rig, R int pos, R ll v)
{
	if (lef == rig)
	{
		tree[now].val[0] = v;
		tree[now].val[1] = v - pos;
		tree[now].val[2] = v + pos;
		return;
	}
	pushdown(now);
	int mid = lef + rig >> 1;
	if (pos <= mid) modify(ls, lef, mid, pos, v);
	else modify(rs, mid + 1, rig, pos, v);
	pushup(now);
}
IN void add(R ll v)
{
	tree[1].tag += v;
	tree[1].val[0] += v;
	tree[1].val[1] += v;
	tree[1].val[2] += v;
}
ll query(R int now, R int lef, R int rig, R int lb, R int rb, R int id)
{
	if (lef >= lb && rig <= rb) return tree[now].val[id];
	pushdown(now);
	int mid = lef + rig >> 1; ll ret = LONG_LONG_MAX;
	if (lb <= mid) ret = query(ls, lef, mid, lb, rb, id);
	if (rb > mid) ret = min(ret, query(rs, mid + 1, rig, lb, rb, id));
	return ret;
}
int main(void)
{
	int a, b, last, cur, del;
	ll res1, res2, res3;
	in(n), in(q), in(a), in(b);
	in(last);
	modify(1, 1, n, b, abs(last - a));
	modify(1, 1, n, a, abs(last - b));
	W (--q)
	{
		in(cur); del = abs(last - cur);
		res1 = query(1, 1, n, cur, cur, 0) + del;
		res2 = query(1, 1, n, 1, cur, 1) + cur;
		res3 = query(1, 1, n, cur + 1, n, 2) - cur;
		res1 = min(res1, min(res2, res3));
		add(del);
		modify(1, 1, n, last, res1);
		last = cur;
	}
	printf("%lld", tree[1].val[0]);
}