#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

template<typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;
    const F f;
    const Monoid M1;
    int sz;
    vector<Monoid> dat;
    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1), sz(1) {
        while (sz < n) sz <<= 1;
        dat.assign(sz * 2, M1);
    }
    void set(int k, const Monoid &x) { dat[k + sz] = x; }
    void build() {
        for (int k = sz - 1; k > 0; k--) {
            dat[k] = f(dat[2 * k], dat[2 * k + 1]);
        }
    }
    void update(int k, const Monoid &x) {
        dat[k += sz] = x;
        while (k >>= 1) dat[k] = f(dat[2 * k], dat[2 * k + 1]);
    }
    Monoid get(int a, int b) {  // [a, b)
        Monoid L = M1, R = M1;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) L = f(L, dat[a++]);
            if (b & 1) R = f(dat[--b], R);
        }
        return f(L, R);
    }
    Monoid operator[](const int &k) const { return dat[k + sz]; }
    friend ostream& operator<<(ostream& os, SegmentTree<Monoid> &seg) {
        for (int i = 0; i < seg.sz; i++) os << seg[i] << " ";
        return os;
    }
};

int main() {
    int n; cin >> n;
    int Q; cin >> Q;
    int a, b; cin >> a >> b; a--, b--;
    vector<int> x(Q + 1);
    x[0] = a;
    for (int q = 1; q <= Q; q++) cin >> x[q], x[q]--;
    const long long INF = 1LL << 60;    // 1.15x10^18
    using ll = long long;
    SegmentTree<ll> dpL(n, [](ll a, ll b) { return min(a, b); }, INF);
    SegmentTree<ll> dpR(n, [](ll a, ll b) { return min(a, b); }, INF);
    dpL.set(b, 0 - b); dpL.build();
    dpR.set(b, 0 + b); dpR.build();
    ll add = 0;
    for (int q = 1; q <= Q; q++) {
        int diff = abs(x[q] - x[q - 1]);
        add += diff;
        ll val = min(dpL.get(0, x[q]) + x[q], dpR.get(x[q], n) - x[q]);
        val -= diff;
        dpL.update(x[q - 1], val - x[q - 1]);
        dpR.update(x[q - 1], val + x[q - 1]);
    }
    ll mi = INF;
    for (int i = 0; i < n; i++) mi = min(mi, dpL[i] + i);
    cout << mi + add << endl;
    return 0;
}
#if 0
2019.12.30

朴素 dp 设 f[i][p][q] 表示前 i 次操作后当前棋子为 (p, q) 的最小代价。
事实上由于第 i 次操作后一定有一个棋子是 x[i] ，因此可以优化一维：
f[i][j] 表示前 i 次操作后当前棋子为 (j, x[i]) 的最小代价。

转移有两种：
1) f[i - 1][j] + |x[i - 1] - x[i]| -> f[i][j]
2) min(f[i - 1][k] + |x[i] - k|) -> f[i][x[i - 1]]
用线段树维护 f[~][j] ，第一种转移就是全局加，第二种是单点取 min 。
第二种转移可以把左边的绝对值拆开：
f[i - 1][k] - k + x[i] (k < x[i])
f[i - 1][k] (k = x[i])
f[i - 1][k] + k - x[i] (k > x[i])
线段树分别维护 f[~][j] - j, f[~][j], f[~][j] + j 即可。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 200005;
ll f[maxn << 2], fa[maxn << 2], fb[maxn << 2], tag;

void modify(int now, int L, int R, int p, ll x) {
	f[now] = std::min(f[now], x);
	fa[now] = std::min(fa[now], x + p);
	fb[now] = std::min(fb[now], x - p);
	if(L == R) return;
	int M = (L + R) >> 1;
	if(p <= M) modify(now << 1, L, M, p, x);
	else modify(now << 1 | 1, M + 1, R, p, x);
}

void build(int now, int L, int R) {
	f[now] = fa[now] = fb[now] = 1000000000000000000;
	if(L == R) return;
	int M = (L + R) >> 1;
	build(now << 1, L, M);
	build(now << 1 | 1, M + 1, R);
}

ll query(int now, int L, int R, int p) {
	if(R < p) return p + fb[now];
	if(L > p) return fa[now] - p;
	if(L == R) return f[now];
	int M = (L + R) >> 1;
	return std::min(query(now << 1, L, M, p), query(now << 1 | 1, M + 1, R, p));
}

int main() {
	int n = read, q = read, a = read, b = read;

	build(1, 1, n);
	modify(1, 1, n, a, 0);
	/* modify(1, 1, n, b, 0); */

	int last = b;
	while(q --) {
		int x = read;
		ll qu = query(1, 1, n, x) + tag;
		/* debug("qu = %lld\n", qu); */
		tag += std::abs(x - last);
		modify(1, 1, n, last, qu - tag);
		last = x;
		/* debug("tag=%lld\n", tag); */
	}

	printf("%lld\n", f[1] + tag);
}
