#include <stdio.h>
#include <bits/stdc++.h>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 200000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);

ll dp[2][N * 4];
ll add[N * 4];
ll cnt_v = 1;

void build(ll n)
{
    while (cnt_v < n)
        cnt_v <<= 1;
    rep(i, 0, cnt_v)
    {
        dp[0][cnt_v - 1 + i] = big - i;
        dp[1][cnt_v - 1 + i] = big + i;
    }
    repb(i, cnt_v - 2, -1)
    {
        dp[0][i] = min(dp[0][i * 2 + 1], dp[0][i * 2 + 2]);
        dp[1][i] = min(dp[1][i * 2 + 1], dp[1][i * 2 + 2]);
    }
}

void push(ll x)
{
    dp[0][x * 2 + 1] += add[x];
    dp[1][x * 2 + 1] += add[x];
    add[x * 2 + 1] += add[x];
    dp[0][x * 2 + 2] += add[x];
    dp[1][x * 2 + 2] += add[x];
    add[x * 2 + 2] += add[x];
    add[x] = 0;
}

void upd(ll x, ll lx, ll rx, ll p, ll v)
{
    if (rx - lx == 1)
    {
        dp[0][x] = min(dp[0][x], v - p);
        dp[1][x] = min(dp[1][x], v + p);
    }
    else
    {
        push(x);
        ll m = (lx + rx) / 2;
        if (p < m)
            upd(x * 2 + 1, lx, m, p, v);
        else
            upd(x * 2 + 2, m, rx, p, v);
        dp[0][x] = min(dp[0][x * 2 + 1], dp[0][x * 2 + 2]);
        dp[1][x] = min(dp[1][x * 2 + 1], dp[1][x * 2 + 2]);
    }
}

/*void add(ll x, ll lx, ll rx, ll l, ll r, ll v)
{
    if (lx >= r || l >= rx)
        return;
    else if (lx >= l && rx <= r)
    {
        dp[0][x] += v;
        dp[1][x] += v;
        add[x] += v;
    }
    else
    {
        push(x);
        add(x * 2 + 1, lx, (lx + rx) / 2, l, r, v);
        add(x * 2 + 2, (lx + rx) / 2, rx, l, r, v);
        dp[0][x] = min(dp[0][x * 2 + 1], dp[0][x * 2 + 2]);
        dp[1][x] = min(dp[1][x * 2 + 1], dp[1][x * 2 + 2]);
    }
}*/

ll get(ll t, ll x, ll lx, ll rx, ll l, ll r)
{
    if (lx >= r || l >= rx)
        return big;
    else if (lx >= l && rx <= r)
        return dp[t][x];
    else
    {
        push(x);
        return min(get(t, x * 2 + 1, lx, (lx + rx) / 2, l, r), get(t, x * 2 + 2, (lx + rx) / 2, rx, l, r));
    }
}

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    ll n, q, A, B;
    cin >> n >> q >> A >> B;
    A--; B--;
    ll a[q];
    rep(i, 0, q)
    {
        cin >> a[i];
        a[i]--;
    }
    build(n);
    upd(0, 0, cnt_v, A, abs(a[0] - B));
    upd(0, 0, cnt_v, B, abs(a[0] - A));
    rep(i, 1, q)
    {
        ll d = min(get(0, 0, 0, cnt_v, 0, a[i] + 1) + a[i], get(1, 0, 0, cnt_v, a[i], n) - a[i]);
        dp[0][0] += abs(a[i] - a[i - 1]);
        dp[1][0] += abs(a[i] - a[i - 1]);
        add[0] += abs(a[i] - a[i - 1]);
        upd(0, 0, cnt_v, a[i - 1], d);
    }
    rep(i, 0, cnt_v - 1)
        push(i);
    ll ans = big;
    rep(i, 0, n)
        ans = min(ans, dp[0][cnt_v - 1 + i] + i);
    cout << ans << endl;
}


Measured memory_bytes: 20224