// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



const int MaxN = 200005;

const long long oo = 1e18;



struct SegmentTree

{

    long long Min[4 * MaxN][3], Lazy[4 * MaxN];

    int Low[4 * MaxN], High[4 * MaxN];

    void InitTree(int x, int L, int R)

    {

        Low[x] = L;

        High[x] = R;

        Lazy[x] = 0;

        Min[x][0] = Min[x][1] = Min[x][2] = oo;

        if (L == R)

        {

            return;

        }

        int Mid = (L + R) / 2;

        InitTree(x * 2, L, Mid);

        InitTree(x * 2 + 1, Mid + 1, R);

    

    }

    void doLazy(int x)

    {

        if (Low[x] != High[x])

        {

            Lazy[x * 2] += Lazy[x];

            Lazy[x * 2 + 1] += Lazy[x];

        }

        for (int i = 0; i < 3; i++)

        {

            Min[x][i] += Lazy[x];

        }

        Lazy[x] = 0;

    }

    void Update(int x, int pos, long long Val)

    {

        doLazy(x);

        if (Low[x] > pos || pos > High[x])

            {return;}

        if (Low[x] == High[x])

        {

            if (Min[x][0] > Val)

            {

                Min[x][0] = Val;

                Min[x][1] = Val - Low[x];

                Min[x][2] = Val + Low[x];

            }

            return;

        }

        Update(x * 2, pos, Val);

        Update(x * 2 + 1, pos, Val);

        for (int i = 0; i < 3; i++)

        {    Min[x][i] = min(Min[x * 2][i], Min[x * 2 + 1][i]);

    }}

    long long Get(int x, int L, int R, int type)

    {

        doLazy(x);

        if (Low[x] > R || High[x] < L)

        {

            return oo;

        }

        if (Low[x] >= L && High[x] <= R)

        {

            return Min[x][type];

        }

        return min(Get(x * 2, L, R, type), Get(x * 2 + 1, L, R, type));

    }

};



int n, q, A, B;

int a[MaxN];

SegmentTree ST;



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    cin >> n >> q >> A >> B;

    for (int i = 1; i <= q; i++)

    {

        cin >> a[i];

    }

    ST.InitTree(1, 1, n);

    ST.Update(1, B, abs(A - a[1]));

    ST.Update(1, A, abs(B - a[1]));

    for (int i = 2; i <= q; i++)

    {

        long long Min = min(ST.Get(1, 1, a[i], 1) + a[i], ST.Get(1, a[i], n, 2) - a[i]);

        ST.Lazy[1] += abs(a[i - 1] - a[i]);

        ST.doLazy(1);

        ST.Update(1, a[i - 1], Min);

    }

    cout << ST.Min[1][0];

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using namespace std;

typedef long long LL;

const int mod = 1e9 + 7;

const int MAXN = 200050;

int n, q, A, lst;

LL tag, mn[MAXN<<2][2];

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

	if(l == r) {

		mn[i][0] = abs(l-A) - l;

		mn[i][1] = abs(l-A) + l;

		return;

	}

	int mid = (l + r) >> 1;

	build(i<<1, l, mid);

	build(i<<1|1, mid+1, r);

	mn[i][0] = min(mn[i<<1][0], mn[i<<1|1][0]);

	mn[i][1] = min(mn[i<<1][1], mn[i<<1|1][1]);

}

LL qry(int i, int l, int r, int x, int y, int o) {

	if(x <= l && r <= y) return mn[i][o];

	int mid = (l + r) >> 1; LL re = 1ll<<60;

	if(x <= mid) re = min(re, qry(i<<1, l, mid, x, y, o));

	if(y > mid) re = min(re, qry(i<<1|1, mid+1, r, x, y, o));

	return re;

}

void upd(int i, int l, int r, int x, LL val) {

	if(l == r) {

		if(val < mn[i][0]+l+tag) {

			mn[i][0] = val-tag-l;

			mn[i][1] = val-tag+l;

		}

		return;

	}

	int mid = (l + r) >> 1;

	if(x <= mid) upd(i<<1, l, mid, x, val);

	else upd(i<<1|1, mid+1, r, x, val);

	mn[i][0] = min(mn[i<<1][0], mn[i<<1|1][0]);

	mn[i][1] = min(mn[i<<1][1], mn[i<<1|1][1]);

}

LL ans;

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

	if(l == r) {

		ans = min(ans, mn[i][0]+l+tag);

		return;

	}

	int mid = (l + r) >> 1;

	dfs(i<<1, l, mid);

	dfs(i<<1|1, mid+1, r);

}

int main () {

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

	build(1, 1, n);

	for(int i = 1, x; i <= q; lst = x, ++i) {

		scanf("%d", &x);

		LL val = qry(1, 1, n, 1, x, 0) + tag + x;

		if(x < n) val = min(val, qry(1, 1, n, x+1, n, 1) + tag - x);

		tag += abs(x-lst);

		upd(1, 1, n, lst, val);

	}

	ans = 1ll<<60;

	dfs(1, 1, n);

	printf("%lld\n", ans);

}

// Fastest known solution for this problem: