//#pragma warning(disable:4996)
//#include <Windows.h>
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

template<class T>
inline void chmin(T& a, T b) {
	a = min(a, b);
}

template<class T>
inline void chmax(T& a, T b) {
	a = max(a, b);
}

void input();
void solve();

void daminput();

int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	input();
	//daminput();
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////

int N, Q;
int A, B;
VI X;

void input() {
	cin >> N >> Q >> A >> B;
	X.resize(Q);
	for (int n = 0; n < Q; n++)
	{
		cin >> X[n];
	}
}

void daminput() {
}

//TT(T,T):=モノイドの乗算
//MT(M,T,LL):=モノイドに対する左作用(第3項は要素数)
//MM(M,M):=左作用の合成
template<class T, class M>
class LazySegtree {
public:
	vector<T> seg;
	vector<M> lazy;   //実、更新の必要性
	typedef function<T(T, T)> TT;
	typedef function<T(M, T, int)> MT;
	typedef function<M(M, M)> MM;
	TT tt;
	MT mt;
	MM mm;
	M Me;
	T Te;
	int snum;   //何回シフトで下段から1に行けるか
	LazySegtree(int N, TT _tt, MT _mtn, MM _mm, T te, M me) {
		int RN = 1;
		snum = 0;
		while (RN < N) {
			RN *= 2;
			snum++;
		}
		Te = te;
		Me = me;
		seg.resize(2 * RN, Te);
		lazy.resize(2 * RN, Me);
		tt = _tt;
		mt = _mtn;
		mm = _mm;
	}
	LazySegtree(vector<T>& vec, TT _tt, MT _mt, MM _mm, T te, M me) {
		int RN = 1;
		snum = 0;
		while (RN < vec.size()) {
			RN *= 2;
			snum++;
		}
		Te = te;
		Me = me;
		seg.resize(2 * RN, Te);
		lazy.resize(2 * RN, Me);
		tt = _tt;
		mt = _mt;
		mm = _mm;
		for (int n = 0; n < vec.size(); n++) seg[RN + n] = vec[n];
		for (int n = RN - 1; n >= 1; n--) {
			seg[n] = tt(seg[2 * n], seg[2 * n + 1]);
		}
	}
	void eval(int k, int l, int r) {
		if (k >= seg.size())return;
		if (lazy[k] == Me)return;
		seg[k] = mt(lazy[k], seg[k], r - l + 1);
		if (k < seg.size() / 2) {
			lazy[2 * k] = mm(lazy[k], lazy[2 * k]);
			lazy[2 * k + 1] = mm(lazy[k], lazy[2 * k + 1]);
		}
		lazy[k] = Me;
	}
	void apply(int a, int b, M m, int k, int l, int r) {
		eval(k, l, r);
		if (r < a || b < l)return;
		if (a <= l && r <= b) {
			lazy[k] = mm(m, lazy[k]);
			eval(k, l, r);
		}
		else {
			apply(a, b, m, 2 * k, l, (l + r) / 2);
			apply(a, b, m, 2 * k + 1, (l + r) / 2 + 1, r);
			seg[k] = tt(seg[2 * k], seg[2 * k + 1]);
		}
	}
	void apply(int a, int b, M m) {
		apply(a, b, m, 1, 0, seg.size() / 2 - 1);
	}
	T get(int a, int b, int k, int l, int r) {
		if (r < a || b < l)return Te;
		eval(k, l, r);
		if (a <= l && r <= b)return seg[k];
		else return tt(get(a, b, 2 * k, l, (l + r) / 2), get(a, b, 2 * k + 1, (l + r) / 2 + 1, r));
	}
	T get(int a, int b) {
		return get(a, b, 1, 0, seg.size() / 2 - 1);
	}
	void set(int n, T t) {
		int RN = seg.size() / 2;
		int l = 0, r = RN - 1;
		for (int t = snum; t > 0; t--) {
			eval((n + RN) >> t, l, r);
			if (((n + RN) >> (t - 1)) & 1) {
				l = ((l + r) >> 1) + 1;
			}
			else {
				r = (l + r) >> 1;
			}
		}
		eval((n + RN), n, n);
		seg[n + RN] = t;
		l = n;
		r = n;
		n += RN;
		while ((n >> 1) > 0) {
			if (n & 1) {
				l = 2 * l - r - 1;
			}
			else {
				r = 2 * r - l + 1;
			}
			n >>= 1;
			eval(n * 2, l, (l + r) >> 1);
			eval(n * 2 + 1, ((l + r) >> 1) + 1, r);
			seg[n] = tt(seg[2 * n], seg[2 * n + 1]);
		}
	}
};
void solve() {
	VI querys(Q + 1, B);
	for (int i = 1; i < Q+1; i++)
	{
		querys[i] = X[i - 1];
	}
	VLL segin(N + 1,1e12);
	segin[A] = 0+A;
	LazySegtree<LL, LL> seg1(segin,
		[](LL a, LL b) {
		return min(a, b);
	}, [](LL m, LL t, int n) {
		if (t == 1e12)return (LL)1e12;
		return t + m;
	}, [](LL a, LL b) {
		return a + b;
	}, 1e12, 0);
	segin[A] = 0 + (N + 1 - A);
	LazySegtree<LL, LL> seg2(segin,
		[](LL a, LL b) {
		return min(a, b);
	}, [](LL m, LL t, int n) {
		if (t == 1e12)return (LL)1e12;
		return t + m;
	}, [](LL a, LL b) {
		return a + b;
	}, 1e12, 0);
	for (int n = 1; n <= Q; n++) {
		int x = querys[n - 1];
		int y = querys[n];
		LL min2 = 1e12;
		if(y-1 >= 1)min2 = seg2.get(1, y-1);
		if (min2 < 1e12)min2 -= N-y+1;
		LL min1 = 1e12;
		if(y+1 <= N)min1 = seg1.get(y+1, N);
		if (min1 < 1e12)min1 -= y;
		LL old = seg1.get(y, y);
		LL w = min(min1, min2);
		w = min(w, old - y);
		if (w < old+labs(y - x)) {
			seg1.set(x, w+x);
			seg2.set(x, w+(N+1-x));
			if (x - 1 >= 1) {
				seg1.apply(1, x - 1, labs(y - x));
				seg2.apply(1, x - 1, labs(y - x));
			}
			if (x + 1 <= N) {
				seg1.apply(x + 1, N, labs(y - x));
				seg2.apply(x + 1, N, labs(y - x));
			}
		}
		else {
			seg1.apply(1, N, labs(y - x));
			seg2.apply(1, N, labs(y - x));
		}
		//for (int n = 1; n <= N; n++)
		//{
		//	LL x = seg1.get(n, n);
		//	if (x == 1e12)cout << "x ";
		//	else cout << x - n << " ";
		//}
		//cout << "\n";
	}
	LL ans = 1e12;
	for (int n = 1; n <= N; n++) {
		LL res = seg1.get(n, n);
		chmin(ans, res - n);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 22396