// ███▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓╬╬╬╬╬╬▓█
// ███▓███████▓▓╬╬╬╬╬╬╬╬╬╬╬╬▓███▓▓▓▓█▓╬╬╬▓█
// ███████▓█████▓▓╬╬╬╬╬╬╬╬▓███▓╬╬╬╬╬╬╬▓╬╬▓█
// ████▓▓▓▓╬╬▓█████╬╬╬╬╬╬███▓╬╬╬╬╬╬╬╬╬╬╬╬╬█
// ███▓▓▓▓╬╬╬╬╬╬▓██╬╬╬╬╬╬▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ████▓▓▓╬╬╬╬╬╬╬▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ███▓█▓███████▓▓███▓╬╬╬╬╬╬▓███████▓╬╬╬╬▓█
// ████████████████▓█▓╬╬╬╬╬▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬█
// ███▓▓▓▓▓▓▓╬╬▓▓▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ████▓▓▓╬╬╬╬▓▓▓▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ███▓█▓▓▓▓▓▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// █████▓▓▓▓▓▓▓▓█▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// █████▓▓▓▓▓▓▓██▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// █████▓▓▓▓▓████▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ████▓█▓▓▓▓██▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ████▓▓███▓▓▓▓▓▓▓██▓╬╬╬╬╬╬╬╬╬╬╬╬█▓╬▓╬╬▓██
// █████▓███▓▓▓▓▓▓▓▓████▓▓╬╬╬╬╬╬╬█▓╬╬╬╬╬▓██
// █████▓▓█▓███▓▓▓████╬▓█▓▓╬╬╬▓▓█▓╬╬╬╬╬╬███
// ██████▓██▓███████▓╬╬╬▓▓╬▓▓██▓╬╬╬╬╬╬╬▓███
// ███████▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬████
// ███████▓▓██▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓████
// ████████▓▓▓█████▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█████
// █████████▓▓▓█▓▓▓▓▓███▓╬╬╬╬╬╬╬╬╬╬╬▓██████
// ██████████▓▓▓█▓▓▓╬▓██╬╬╬╬╬╬╬╬╬╬╬▓███████
// ███████████▓▓█▓▓▓▓███▓╬╬╬╬╬╬╬╬╬▓████████
// ██████████████▓▓▓███▓▓╬╬╬╬╬╬╬╬██████████
// ███████████████▓▓▓██▓▓╬╬╬╬╬╬▓███████████
//#include "grader.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <cassert>
#define For(i, a, b) for (int i = a; i < b; ++i)
#define Out(i, a, b) for (int i = a - 1; i >= b; --i)
#define pb push_back
#define x first
#define y second
#define files(FileName) read(FileName); write(FileName)
#define read(FileName) freopen((FileName + ".in").c_str(), "r", stdin)
#define write(FileName) freopen((FileName + ".out").c_str(), "w", stdout)
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }

using namespace std;

typedef long long base;
typedef pair <base, base> point;

const string FILENAME = "input";
const int MAXN = 1 << 18;
const base INF = 2e15;

struct seg_tree {
    base mod[MAXN * 2];
    base tree[MAXN * 2][2];
    seg_tree() {
        for (int i = 0; i < MAXN * 2; ++i) {
            mod[i] = 0;
            tree[i][0] = tree[i][1] = INF;
        }
    }
    void push(int i) {
        tree[i][0] += mod[i];
        tree[i][1] += mod[i];
        if (i < MAXN) {
            mod[i * 2] += mod[i];
            mod[i * 2 + 1] += mod[i];
        }
        mod[i] = 0;
    }
    void push_to_root(int i) {
        if (i == 0) return;
        push_to_root(i >> 1);
        push(i);
        push(i ^ 1);
    }
    void change(int i, base d) {
        push_to_root(i + MAXN);
        tree[i + MAXN][0] = d - i;
        tree[i + MAXN][1] = d + i;
        i += MAXN;
        while (i > 1) {
            i >>= 1;
            tree[i][0] = min(tree[i * 2][0], tree[i * 2 + 1][0]);
            tree[i][1] = min(tree[i * 2][1], tree[i * 2 + 1][1]);
        }
    }
    point get(int i, int L, int R, int Ln, int Rn) {
        push(i);
        if (Rn <= L || R <= Ln)
            return {INF, INF};
        if (Ln <= L && R <= Rn) {
            return {tree[i][0], tree[i][1]};
        }
        int M = (L + R) >> 1;
        point ans1 = get(i * 2, L, M, Ln, Rn);
        point ans2 = get(i * 2 + 1, M, R, Ln, Rn);
        return {min(ans1.x, ans2.x), min(ans1.y, ans2.y)};
    }
};

int n, m, A, B;
long long lst;
seg_tree box;

int main() {
    srand(time(0));
    //read(FILENAME);
    ios::sync_with_stdio(0);
    cin >> n >> m >> A >> B;
    box.change(A, 0);
    lst = B;
    for (int i = 0; i < m; ++i) {
        cin >> B; 
        auto ans1 = box.get(1, 0, MAXN, 0, B);
        auto ans2 = box.get(1, 0, MAXN, B, MAXN);
        //cout << ans1.x << ' ' << ans2.y << endl;
        long long ans = min(ans1.x + B, ans2.y - B);
        //cout << ans << endl;
        box.mod[1] += abs(lst - B);
        box.change(lst, ans);
        lst = B;
    }
    long long ans = INF;
    for (int i = 0; i < MAXN; ++i) {
        box.push_to_root(i + MAXN);
        chkmin(ans, box.tree[i + MAXN][0] + i);
    }
    cout << ans << endl;
}



Measured memory_bytes: 12544