#include <bits/stdc++.h>
#define ADD(a, b) a = (a + (ll)b) % mod
#define MUL(a, b) a = (a * (ll)b) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rer(i, a, b) for(int i = a - 1; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<int, pi> ppi;
typedef vector<ll> vec;

const int MAX_N = 200010;
const double eps = 1e-6;
const ll mod = 1000000007;
const ll inf = 1LL << 59;

void Debug() {cout << '\n'; }

template<class FIRST, class... REST> 
void Debug(FIRST arg, REST... rest) { cout << arg << " "; Debug(rest...); }

template<class T>
ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";
	if(!v.empty()) {
		rep(i, 0, (int)v.size() - 1) out << v[i] << ", ";
		out << v.back();
	}
	out << "]";
  return out;
}

template<class S, class T>
ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";
	return out;
}

///g++ -g3 -std=c++0x -DLOCAL -Wall -ftrapv -D_GLIBCXX_DEBUG -Wl,-stack,268435456 -o
///g++ -O2 -std=c++0x -DLOCAL -Wall -Wl,-stack,268435456 -o

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

struct node {
	ll sum, lazy;
	node() : sum(0), lazy(0){}
	node(ll sum, ll lazy) : sum(sum), lazy(lazy){}
};

int N;
node seg1[200000 * 4], seg2[200000 * 4];

inline void lazy_eval(node* seg, int k, int l, int r) {
	if(seg[k].lazy) {
		seg[k * 2 + 1].sum += seg[k].lazy;//if range_min, erase (m - l)
		seg[k * 2 + 1].lazy += seg[k].lazy;
		seg[k * 2 + 2].sum += seg[k].lazy;//here too
		seg[k * 2 + 2].lazy += seg[k].lazy;
		seg[k].lazy = 0;
	}
}

void update(node* seg, int a, int b, ll s, int k = 0, int l = 0, int r = N) {
	if(b <= l || r <= a) return;
	if(a <= l && r <= b) {
		seg[k].sum += s;//here too
		seg[k].lazy += s;
	}
	else {
		int m = (l + r) / 2;
		lazy_eval(seg, k, l, r);
		update(seg, a, b, s, k * 2 + 1, l, m);
		update(seg, a, b, s, k * 2 + 2, m, r);
		seg[k].sum = min(seg[k * 2 + 1].sum, seg[k * 2 + 2].sum);
	}
}

ll get_sum(node* seg, int a, int b, int k = 0, int l = 0, int r = N) {
	if(b <= l || r <= a) return inf * 2;
	if(a <= l && r <= b) return seg[k].sum;
	else {
		int m = (l + r) / 2;
		lazy_eval(seg, k, l, r);
		ll lsum = get_sum(seg, a, b, k * 2 + 1, l, m);
		ll rsum = get_sum(seg, a, b, k * 2 + 2, m, r);
		return min(lsum, rsum);
	}
}

int Q, A, B;
int C[MAX_N];

void show_seg(node* seg) {
	vector<ll> vec;
	rep(i, 0, N) {
		vec.push_back(get_sum(seg, i, i + 1));
	}
	debug(vec);
}

void solve() {
	cin >> N >> Q >> A >> B; A--; B--;
	C[0] = B;
	rep(i, 1, Q + 1) {
		cin >> C[i]; C[i]--;
	}
	rep(i, 0, N) {
		if(i != A) {
			update(seg1, i, i + 1, inf - i);
			update(seg2, i, i + 1, inf + i);
		}
		else {
			update(seg1, i, i + 1, -i);
			update(seg2, i, i + 1, i);
		}
	}
	rep(i, 1, Q + 1) {
		ll m = get_sum(seg1, 0, C[i] + 1) + C[i];
		MIN(m, get_sum(seg2, C[i], N) - C[i]);
		update(seg1, 0, N, abs(C[i] - C[i - 1]));
		update(seg2, 0, N, abs(C[i] - C[i - 1]));
		ll r = get_sum(seg1, C[i - 1], C[i - 1] + 1) + C[i - 1];
		if(r > m) {
			update(seg1, C[i - 1], C[i - 1] + 1, m - r);
			update(seg2, C[i - 1], C[i - 1] + 1, m - r);
		}
	}
	ll res = inf;
	rep(i, 0, N) {
		MIN(res, get_sum(seg1, i, i + 1) + i);
	}
	cout << res << "\n";
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);	
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 25984