#include <bits/stdc++.h>
using namespace std;

template <typename T> void setmin(T& a, T b) {
	if (b < a) a = b;
}

using i64 = int64_t;
const i64 INF = 1e17;

map<int, i64> dp;

i64 query_pt(int x) {
	i64 ans = INF;
	auto it = dp.lower_bound(x);
	if (it != dp.end()) {
		setmin(ans, (it->first - x) + it->second);
	}
	if (it != dp.begin()) {
		--it;
		setmin(ans, (x - it->first) + it->second);
	}
	return ans;
}

void insert_pt(int x, i64 v) {
	if (query_pt(x) <= v) return;

	auto it = dp.lower_bound(x);
	while (it != dp.end()) {
		if (v + (it->first - x) <= it->second) {
			it = dp.erase(it);
		} else {
			break;
		}
	}
	while (it != dp.begin()) {
		--it;
		if (v + (x - it->first) <= it->second) {
			it = dp.erase(it);
		} else {
			break;
		}
	}
	dp[x] = v;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);

	int N, Q, A, B; cin >> N >> Q >> A >> B;

	dp[A] = 0;
	int prv = B;
	i64 cval = 0;
	for (int q = 0; q < Q; q++) {
		int x; cin >> x;

		int d = abs(x - prv);
		cval += d;

		insert_pt(prv, query_pt(x) - d);

		prv = x;
	}

	i64 ans = INF;
	for (auto it : dp) {
		setmin(ans, it.second);
	}
	ans += cval;
	cout << ans << '\n';

	return 0;
}
