#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>

using namespace std;

//template<typename T>
//using Matrix2D = std::vector<vector<T>>;

const bool debug = false;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
//const int mod = int(1e9) + 7;
const int inf = 1e9;
const long long infLL = 1e11;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 200500; //       e5
const int SZ = 1100;
//const int delta = 1 << 19;

map<int, long long> second_pos;
int first_pos;
long long to_add = 0;

long long min(const long long &x, const long long &y){
    if(x < y) return x; return y;
}

long long ab(long long x){
    if(x < 0) return -x;
    return x;
}

long long check_ans(long long x){
    auto it = second_pos.lower_bound(x);
    long long ans = infLL;
    if(it != second_pos.end()) ans = it->second + ab(x - it->first);
    if(it != second_pos.begin()){
        it--;
        ans = min(ans, it->second + ab(x - it->first));
    }
    return ans + to_add;
}

void add_to_set(int x, long long ans){
    auto it = second_pos.lower_bound(x);
    while(it != second_pos.end()){
        if(ans + it->first - x  <= it->second){
            auto it2 = it;
            it++;
            second_pos.erase(it2);
        }else break;
    }
    if(it == second_pos.begin()) return;
    it--;
    while(true){
        if(ans + x - it->first <= it->second){
            if(it == second_pos.begin()){
                second_pos.erase(it);
                return;
            }
            auto it2 = it;
            it--;
            second_pos.erase(it2);
        } else break;
    }
}

void proc(int x){
    int other = first_pos;
    long long ans = check_ans(x);
    to_add += abs(x - first_pos);
    first_pos = x;
    long long r2 = check_ans(other);
    //cerr <<  " ! " << ans <<  " " << r2 << " " << other << endl;
    if(r2 > ans){
        add_to_set(other, ans - to_add);
        second_pos[other] = ans - to_add;
    }
}

void brute(){
    int n, q;
    int a, b;
    cin >> n >> q >> a >> b;
    map<pair<int,int>, int> sp;
    sp[{a,b}] = 1;
    q -= 12;
    while(q--){
        int x;
        cin >> x;
        map<pair<int,int>, int> sp2;
        for(auto it = sp.begin(); it != sp.end(); it++){
            pair<int,int> a = it->first;
            int &r1 = sp2[{x, a.second}];
            if(r1 == 0) r1 = inf;
            r1 = min(r1, it->second + ab(a.first - x));

            int &r2 = sp2[{a.first, x}];
            if(r2 == 0) r2 = inf;
            r2 = min(r2, it->second + ab(a.second - x));
        }
        swap(sp, sp2);
    }
    for(auto it = sp.begin();it != sp.end(); it++){
        if(it->second < 22)
        cout << it->first.first << ' ' << it->first.second << ' ' << it->second - 1 << endl;
    }

}

int main()
{
    //brute(); return 0;
    ios_base::sync_with_stdio(false);
    int n, q;
    int s_p;
    cin >> n >> q >> first_pos >> s_p;
    to_add = 0;
    second_pos[s_p] = 0;
    while(q--){
        int x;
        cin >> x;
        proc(x);
            //cerr << "first "  << first_pos << " " <<to_add << ":\n";
        //for(auto it = second_pos.begin(); it != second_pos.end(); it++){
            //cerr << it->first <<' ' << it->second << endl;
        //}

    }
    long long ans = infLL;
    for(auto it = second_pos.begin(); it != second_pos.end(); it++){
        ans = min(ans, it->second);
    }
    ans += to_add;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256