#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define int long long
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (ll i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((ll)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <ll, ll> pii ;
typedef vector <ll> vi ;
typedef vector <pii> vii ;
typedef queue <ll> qi ;
typedef queue <pii> qii ;
typedef set <ll> si ;
typedef map <ll, ll> mii ;
typedef map <string, ll> msi ;
const ll maxn = 2e6 + 100 ;
const ll inf = 0x3f3f3f3f ;
const ll iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 998244353 ;
const double eps = 1e-7 ;
template <class T = ll> T chmin(T &a, T b) { return a = min(a, b);}
template <class T = ll> T chmax(T &a, T b) { return a = max(a, b);}
template <class T = ll> T read()
{
	T f = 1, a = 0;
	char ch = getchar() ;
	while(!isdigit(ch)) { if(ch == '-') f = -1 ; ch = getchar() ; }
	while(isdigit(ch)) { a = (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	return a * f ;
}

ll n, m, x, y, ans = linf;

ll a[maxn], pre[maxn], f[2][maxn];

struct binary_indexed_tree
{
	ll val[maxn];
	void init()
	{
		rep(i, 1, n) val[i] = linf;
	}
	void modify(ll pos, ll x)
	{
		for(ll i = pos; i <= n; i += lowbit(i)) chmin(val[i], x);
	}
	ll query(ll pos)
	{
		ll ret = linf;
		for(ll i = pos; i; i -= lowbit(i)) chmin(ret, val[i]);
		return ret;
	}
}
bit[2][2];

signed main()
{
	n = read(), m = read(), x = read(), y = read();
	rep(i, 1, m) a[i] = read();
	rep(i, 2, m) pre[i] = pre[i - 1] + abs(a[i] - a[i - 1]);
	f[0][0] = abs(x - a[1]), f[1][0] = abs(y - a[1]);
	bit[0][0].init(), bit[0][1].init();
	bit[1][0].init(), bit[1][1].init();
	bit[0][0].modify(y, f[0][0] - pre[1] - y), bit[0][1].modify(n - y + 1, f[0][0] - pre[1] + y);
	bit[1][0].modify(x, f[1][0] - pre[1] - x), bit[0][1].modify(n - x + 1, f[1][0] - pre[1] + x);
	rep(i, 1, m - 1)
	{
		// printf("%lld %lld %lld %lld\n", bit[0][0].query(a[i + 1]), bit[1][0].query(a[i + 1]), bit[0][1].query(n - a[i + 1] + 1), bit[1][1].query(n - a[i + 1] + 1));
		f[0][i] = min(bit[1][0].query(a[i + 1]) + pre[i] + a[i + 1], bit[1][1].query(n - a[i + 1] + 1) + pre[i] - a[i + 1]);
		f[1][i] = min(bit[0][0].query(a[i + 1]) + pre[i] + a[i + 1], bit[0][1].query(n - a[i + 1] + 1) + pre[i] - a[i + 1]);
		bit[0][0].modify(a[i], f[0][i] - pre[i + 1] - a[i]), bit[0][1].modify(n - a[i] + 1, f[0][i] - pre[i + 1] + a[i]);
		bit[1][0].modify(a[i], f[1][i] - pre[i + 1] - a[i]), bit[1][1].modify(n - a[i] + 1, f[1][i] - pre[i + 1] + a[i]);
	}
	// rep(i, 0, m - 1) printf("%lld %lld\n", f[0][i], f[1][i]);
	rep(i, 0, m - 1) ans = min(ans, min(f[0][i], f[1][i]) - pre[i + 1] + pre[m]);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 28416