#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const ll INF = (ll)1e17;
struct Node
{
    int l, r;
    ll val;
    ll toAdd;
    
    Node() : l(), r(), val(INF), toAdd(0) {}
    Node(int _l, int _r) : l(_l), r(_r), val(INF), toAdd(0) {}
};
const int N = 1 << 18;
Node tree[2][2 * N];
int n, q;

void build()
{
    for (int i = 0; i < N; i++)
        tree[0][N + i] = tree[1][N + i] = Node(i, i + 1);
    for (int i = N - 1; i > 0; i--)
        tree[0][i] = tree[1][i] = Node(tree[0][2 * i].l, tree[0][2 * i + 1].r);
    return;
}

void push(int k, int v)
{
    if (v >= N) throw;
    if (tree[k][v].toAdd == 0) return;
    for (int u = 2 * v; u < 2 * v + 2; u++)
    {
        tree[k][u].toAdd += tree[k][v].toAdd;
        tree[k][u].val += tree[k][v].toAdd;
    }
    tree[k][v].toAdd = 0;
    return;
}

void update(int k, int v)
{
    if (v >= N) throw;
    tree[k][v].val = min(tree[k][2 * v].val, tree[k][2 * v + 1].val);
    return;
}

void addOnSegm(int k, int v, int l, int r, ll d)
{
    if (l <= tree[k][v].l && tree[k][v].r <= r)
    {
        tree[k][v].toAdd += d;
        tree[k][v].val += d;
        return;
    }
    if (l >= tree[k][v].r || tree[k][v].l >= r) return;
    push(k, v);
    addOnSegm(k, 2 * v, l, r, d);
    addOnSegm(k, 2 * v + 1, l, r, d);
    update(k, v);
    return;
}
void setInPoint(int k, int v, int p, ll d)
{
    if (tree[k][v].l > p || tree[k][v].r <= p) return;
    if (v >= N)
    {
        tree[k][v].val = d;
        return;
    }
    push(k, v);
    setInPoint(k, 2 * v, p, d);
    setInPoint(k, 2 * v + 1, p, d);
    update(k, v);
    return;
}
ll getInPoint(int k, int v, int p)
{
    if (v >= N) return tree[k][v].val;
    push(k, v);
    int m = (tree[k][v].l + tree[k][v].r) / 2;
    if (p < m)
        return getInPoint(k, 2 * v, p);
    else
        return getInPoint(k, 2 * v + 1, p);
}
ll getMinOnSegm(int k, int v, int l, int r)
{
    if (l <= tree[k][v].l && tree[k][v].r <= r)
        return tree[k][v].val;
    if (l >= tree[k][v].r || tree[k][v].l >= r)
        return INF;
    push(k, v);
    return min(getMinOnSegm(k, 2 * v, l, r), getMinOnSegm(k, 2 * v + 1, l, r));
}

void printArr()
{
    for (int i = 1; i <= n; i++)
        printf("%lld ", getInPoint(0, 1, i) + i);
    printf("\n");
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    int A, B;
    scanf("%d%d%d%d", &n, &q, &A, &B);

    build();
    for (int k = 0; k < 2; k++)
        for (int i = 1; i <= n; i++)
            setInPoint(k, 1, i, INF);
    setInPoint(0, 1, A, -A);
    setInPoint(1, 1, A, A);
    A = B;
    while(q--)
    {
        scanf("%d", &B);
        ll val = min(getMinOnSegm(0, 1, 1, B + 1) + B, getMinOnSegm(1, 1, B, n + 1) - B);
        //printArr();
        for (int k = 0; k < 2; k++)
            addOnSegm(k, 1, 1, n + 1, abs(B - A));
        if (val - A < getInPoint(0, 1, A))
            setInPoint(0, 1, A, val - A);
        if (val + A < getInPoint(1, 1, A))
            setInPoint(1, 1, A, val + A);
        A = B;
    }
    ll ans = INF;
    for (int i = 1; i <= n; i++)
        ans = min(ans, getInPoint(0, 1, i) + i);
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 25340