#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

/*
 * Let dp[i][a][b] be the minimum cost required to process the first i
 * queries such that the tokens are at a and b after the queries. This
 * DP works in O(N^3). We'll improve this.
 *
 * Let dp[i][a] be the minimum cost required to process the first i
 * queries such that the tokens are at a and xi after the queries. This
 * DP works in O(N^2).
 *
 * => because at i, we know one of the location is xi
 *
 * Suppose that we want to convert dp(i-1,) array to dp(i,) array:
 *
 * dp[i-1][1], dp[i-1][2], .., dp[i-1][n],
 * dp[i][1],   dp[i][2], ..,   dp[i][n].
 *
 * The following operations are required:
 *
 * 1. Add |x[i−1] - xi| to the whole array.
 * => if we move x[i-1] to xi
 * => this means a range add for [1,N] (need a tree to optimize time)
 *
 * 2. Compute min{j=1,2,..,n}(dp[i-1][j] + |j-xi|).
 * => if we move j to xi
 *
 * This can be done by two RMQs: one of them holds the values of
 * dp[i−1][j]-j and the other one holds the values of dp[i-1][j]+j.
 *
 * => In case of moving from j to xi,
 * => if j < xi, dp[i-1][j] + xi-j     j   x[i]    j
 * =>    j > xi, dp[i-1][j] + j-xi;    * -d- * -d- *
 * => this means we need to find min in 2 ranges: [1,xi] and [xi,N]
 * => we can have 2 segtrees, one for dp(i,j)-j, one for dp(i,j)+j
 * => when we query [1,xi], we query segtree for dp(i,j)-j
 * => ..            [xi,N], ..       ..          dp(i,j)+j
 * => this also implies that we save the dp values directly side the
 * => segtree.
 */

const LL inf = 1e15;
const int maxn = 1e6;           /* big enough for all insert ops */
/*
 * Initial array A[]; this is only used to build the initial tree, after
 * that, it is no long needed. The updated information is stored inside
 * the tree.
 */
LL _A[maxn];
/*
 * In theory, assume the input A[1,n], we can add 2 sentinel elements
 * A[0] and A[n+1].
 *
 * root A[0]    For a given input A[1,n], root corresponds to A[0]
 *         \    (1 less than the first); and ch[root][1] corresponds to
 *      A[n+1]  A[n+1] (1 more than the last); such that ch[root][1][0]
 *         /    is the root for all elements for [1,n].
 * [keytree]
 *  /A[1,n]\
 *
 * root A[L-1]  To query [L,R], we want to rotate A[L-1] to root and
 *         \    A[R+1] to ch[root][1], such that [L,R] become the
 *      A[R+1]  [keytree]
 *         / \
 * [keytree]  [..]
 *  /A[L,R]\
 */
template <class T>
struct Tree {
    /*
     * cnt is for allocating tree node, the storage is sz[],ch[],..,val[],
     * etc.
     */
    int cnt,root;              /* root starts from 1, node[0] is null */
    int sz[maxn],ch[maxn][2],pre[maxn];
    /* add, rev (for reverse) are lazy */
    T add[maxn],rev[maxn],minn[maxn],val[maxn];

    void init(const int n, const T A[])
    {
        cnt = root = 0;
        /* node[0] is the null node */
        sz[0] = ch[0][0] = ch[0][1] = pre[0] = 0; add[0] = rev[0] = 0;
        minn[0] = val[0] = inf;
        root = newnode(inf);    /* inf for minn */
        pre[root] = 0;
        const int ch1 = ch[root][1] = newnode(inf);
        pre[ch1] = root;
        sz[root] = 2;
        /*
         *  1(0)        1st node is root, corresponding to 0
         *   \          2nd node is ch1,  ..               n+1
         *    2(n+1)
         *   /
         * 1..n
         *                                                    8(8)
         * for A[1..10)  | 1| 2| 3| 4| 5| 6| 7| 8| 9|10|      / \
         *    node id:     5  4  6  7  3  9 10  8 11 12    9(6) 11(9)
         *                                                   \     \
         *                                                  10(7) 12(10)
         *
         * Tree is created based on A[] index ordering (node id does not
         * match the index value), and is maintained as invarient.
         */
        ch[ch1][0] = build(1,n,ch1,A);
        pushup(ch1);
        pushup(root);
    }

    int newnode(const T v)
    {
        /* cnt not reused, maxn must be big enough for all insert ops */
        const int x = ++cnt;
        ch[x][0] = ch[x][1] = add[x] = rev[x] = 0;
        sz[x] = 1; minn[x] = val[x] = v;
        return x;
    }

    int build(const int L, const int R, const int parent, const T A[])
    {
        if (L > R)
            return 0;
        const int m = (L+R)/2;
        const int t = newnode(A[m]);
        ch[t][0] = build(L,m-1,t,A);
        ch[t][1] = build(m+1,R,t,A);
        pre[t] = parent;
        pushup(t);
        return t;
    }

    void pushup(const int x)
    {
        sz[x] = sz[ch[x][0]] + sz[ch[x][1]] + 1;
        minn[x] = min(min(minn[ch[x][0]], minn[ch[x][1]]), val[x]);
    }

    void pushdown(const int x)
    {
        if (rev[x]) {
            if (ch[x][0])
                rev[ch[x][0]] ^= 1;
            if (ch[x][1])
                rev[ch[x][1]] ^= 1;
            swap(ch[x][0], ch[x][1]);
            rev[x] ^= 1;
        }
        if (add[x]) {
            if (ch[x][0]) {
                add[ch[x][0]] += add[x];
                minn[ch[x][0]] += add[x];
                val[ch[x][0]] += add[x];
            }
            if (ch[x][1]) {
                add[ch[x][1]] += add[x];
                minn[ch[x][1]] += add[x];
                val[ch[x][1]] += add[x];
            }
            add[x]=0;
        }
    }

    /* rotate and splay */

    /* direction of x relative pre[x]. 0-lft, 1-rht. */
    bool dir(const int x)
    { return ch[pre[x]][1] == x; }

    /* link x under y in d direction */
    void link(const int x, const int y, const int d)
    {
        if (y)
            ch[y][d] = x;
        if (x)
            pre[x] = y;
    }

    void rotate(const int x)
    {
        /*
         *     y           x
         *    / \         / \
         *  [x]     <->     [y]
         *  / \             / \
         */
        const int y = pre[x];
        const bool d = dir(x);
        pushdown(y);
        pushdown(x);
        link(x,pre[y],dir(y));
        link(ch[x][d^1],y,d);
        link(y,x,d^1);
        pushup(y);
    }

    /* splay x under parent */
    void splay(const int x, const int parent)
    {
        pushdown(x);
        while (pre[x] != parent) {
            if (pre[pre[x]] == parent)
                rotate(x);      /* simple rotation */
            else {
                /*
                 *       z          x
                 *      / \        / \
                 *     y              y
                 *    / \    <->     / \
                 *  [x]                [z]
                 *  / \                / \
                 */
                if (dir(x) == dir(pre[x]))
                    rotate(pre[x]); /* zig-zig */
                else
                    rotate(x);      /* zig-zag */
                rotate(x);
                /*
                 *    z           x             y
                 *   / \         / \           / \
                 *  y           /   \             z
                 * / \    ->   y     z    <-     / \
                 *   [x]      / \   / \        [x]
                 *   / \                       / \
                 */
            }
        }
        pushup(x);
        if (parent == 0)
            root = x;
    }

    /* kth element splay to under go(al) */
    void rotate_k2go(int k, const int go)
    {
        int x = root;
        pushdown(x);
        while (sz[ch[x][0]] != k) {
            if (sz[ch[x][0]] > k)
                x = ch[x][0];
            else {
                k -= (sz[ch[x][0]]+1);
                x = ch[x][1];
            }
            pushdown(x);
        }
        splay(x,go);
    }

    int get(const int L, const int R)
    {
        /*
         * this is a crucial helper
         *
         *    L-1 (root)      It gets the tree in this shape,
         *     \              which is referred as the 'keytree'
         *      R+1 (x)       position.
         *      /
         * /L..R\-(keytree)
         */
        rotate_k2go(L-1,0);
        rotate_k2go(R+1,root);
        return ch[root][1];
    }

    /* poj 3580 specific */

    void INSERT(const int x, const T val)
    {
        /*
         *    x (root)        Insert between position x and x+1.
         *     \              The 2 rotate_k2go() make ch[x+1][0] null,
         *      x+1           which is also the insertion point.
         *      / \
         * insert  /x+2 ..\
         * point
         */
        rotate_k2go(x,0);
        rotate_k2go(x+1,root);
        ch[ch[root][1]][0] = newnode(val);
        pre[ch[ch[root][1]][0]] = ch[root][1];
        pushup(ch[root][1]);
        pushup(root);
    }

    void DELETE(const int p)
    {
        /*
         *    p-1 (root)
         *     \              The get() make ch[x][0] the P point,
         *      p+1 (x)       which is also the deletion point.
         *      / \
         *     p   /p+2 ..\
         * delete
         * point
         */
        const int x = get(p,p);
        ch[x][0] = 0;
        pushup(x);
        pushup(root);
    }

    /* add v to all elements in range [L,R] */
    void ADD(const int L, const int R, const T v)
    {
        const int x = get(L,R);
        add[ch[x][0]] += v; minn[ch[x][0]] += v; val[ch[x][0]] += v;
        pushup(x);
        pushup(root);
    }

    /* get min in range [L,R] */
    T MIN(const int L, const int R)
    {
        const int x = get(L,R); /* get() return ch[root][1] */
        return minn[ch[x][0]];  /* ch[root][1][0] */
    }

    void REVERSE(const int L, const int R)
    {
        const int x = get(L,R);
        rev[ch[x][0]] ^= 1;     /* toggle odd/even number */
    }

    void REVOLVE(const int L, const int R, int t)
    {
        const int len = (R-L+1);
        t = (t%len + len)%len;
        if (t == 0)
            return;
        REVERSE(L,R-t);         /* hand-wave rotation alg. */
        REVERSE(R-t+1,R);
        REVERSE(L,R);
    }
};
Tree<LL> S,T;

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    int N,Q,A,B;
    while (cin >> N >> Q >> A >> B) {
        FOR(i,1,N+2)
            _A[i] = inf/1e3;    /* need to be something < inf */
        _A[A] = 0;
        S.init(N+1,_A);
        T.init(N+1,_A);
        int prex = B;
        S.ADD(A,A,-A);          /* dp(i-1,j)-j */
        T.ADD(A,A,+A);          /* dp(i-1,j)+j */
        FOR(i,0,Q) {
            int x; cin >> x;
            /* move x[i-1] to x[i], j remains the same */
            /* dp(i,j) = dp[i-1][j] + |x[i]-x[i-1]| */
            const int dx = abs(x-prex);
            S.ADD(1,N,dx);
            T.ADD(1,N,dx);
            const LL blah = T.MIN(N,N);
            /* move j to x[i] */
            /* dp(i,j) = min{dp(i-1,j) + |x[i]-j|} for j in [1,N] */
            const int j = prex;
            const LL a = S.MIN(1,x) - dx + x;
            const LL b = T.MIN(x,N) - dx - x;
            const LL c = min(a,b);
            if (S.MIN(j,j) > c-j) {
                /* S.DELETE(j); S.INSERT(j-1,c-j); */
                const LL x = S.MIN(j,j);
                S.ADD(j,j,-x+c-j); /* update */
            }
            if (T.MIN(j,j) > c+j) {
                /* T.DELETE(j); T.INSERT(j-1,c+j); */
                const LL x = T.MIN(j,j);
                T.ADD(j,j,-x+c+j); /* update */
            }
            prex = x;
        }
        LL ans = inf;
        FOR(j,1,N+1)
            ans = min(ans, S.MIN(j,j)+j);
        FOR(j,1,N+1)
            ans = min(ans, T.MIN(j,j)-j);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 54272