#include<bits/stdc++.h>
using namespace std;
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}

#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<int, int>;

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

	int n, q, a, b;
	cin >> n >> q >> a >> b;

	vector<int> e(q + 2);
	REP(i, q) cin >> e[i + 2];
	e[0] = a, e[1] = b;
	q += 2;

	int cap = 5e2;
	LL inf = 1e18;
	vector<LL> dp(cap, inf);
	dp[0] = 0;

	FOR(i, 1, q - 2) {
		vector<LL> nt(cap, inf);
		REP(j, cap) {
			if(dp[j] == inf) continue;
			int x = e[i];
			int y = e[i - 1 - j];
			int m = e[i + 1];

			nt[0] = min(nt[0], dp[j] + abs(m - y));
			if(j + 1 < cap) nt[j + 1] = min(nt[j + 1], dp[j] + abs(m - x));
		}
		swap(dp, nt);
	}

	LL ans = inf;
	for(LL &x : dp)
		ans = min(ans, x);

	cout << ans << "\n";
}
