#define ONLINE_JUDGE
// {{{ Includes
#ifndef ONLINE_JUDGE
#pragma clang diagnostic warning "-Wall"
#pragma clang diagnostic warning "-Wextra"
#pragma clang diagnostic warning "-Weverything"
#pragma clang diagnostic warning "-Wconversion"
#pragma clang diagnostic ignored "-Wvla"
#pragma clang diagnostic ignored "-Wvla-extension"
#pragma clang diagnostic ignored "-Wshadow"
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
#pragma clang diagnostic ignored "-Wunused-macros"
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wsign-conversion"
#pragma clang diagnostic ignored "-Wsign-compare"
#pragma clang diagnostic ignored "-Wold-style-cast"
#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
#pragma clang diagnostic ignored "-Wglobal-constructors"
#pragma clang diagnostic ignored "-Wunused-const-variable"
#pragma clang diagnostic ignored "-Wpadded"
#pragma clang diagnostic ignored "-Wfloat-equal" // it's fine
#pragma clang diagnostic ignored "-Wdouble-promotion" // also
#endif

#include <unordered_map>
#include <random>
#include <climits>
#include <array>
#include <fstream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <queue>
#include <cstring>
#include <limits>
#include <chrono>
#include <unistd.h>
using namespace std;
// }}}
// {{{ Utilities
#ifdef ONLINE_JUDGE
static bool debug = false;
#else
static bool debug = true;
#endif
#define db(x) #x << "=" << (x) << " "
#define dprintf debug && printf

#define All(x) x.begin(), x.end()
#define Loop(i, n) for (int i = 0; i < int(n); ++i)
template <typename T, typename Q, typename S>
bool Bounded(const T &x, const Q &a, const S &b) { return a <= x && x <= b; }

typedef long double Real;
const Real pi = 4*atan(Real(1.0));
const Real Inf = numeric_limits<Real>::infinity();
// https://github.com/JuliaLang/julia/blob/master/base/floatfuncs.jl
Real isapprox(Real x, Real y, Real rtol = sqrt(numeric_limits<Real>::epsilon()), Real atol = Real(0.0), bool nans = false) { return x == y || (nans && isnan(x) && isnan(y)) || (isfinite(x) && isfinite(y) && abs(x - y) <= atol + rtol*max(abs(x), abs(y))); }
typedef long long int ll;
typedef vector<Real> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<bool> Vb;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

template <typename T> int sz(const T &x) { return (int)x.size(); }
template <typename T, typename Q> bool mem(const T &s, const Q &x) { return s.find(x) != s.end(); }
template <typename T> void push(vector<T>& c, const T& e) { c.push_back(e); }
template <typename T> void push(queue<T>& c, const T& e) { c.push(e); }
template <typename T> void push(set<T>& c, const T& e) { c.insert(e); }
template <typename T> T pop(vector<T>& v) { assert(!v.empty()); T u = v.back(); v.pop_back(); return u;}
template <typename T, typename... Args> auto emplace(vector<T>& c, Args&&... args) -> decltype(c.emplace_back(args...)) { c.emplace_back(args...); }
template <typename T, typename... Args> auto emplace(queue<T>& c, Args&&... args) -> decltype(c.emplace(args...)) { c.emplace(args...); }
template <typename T, typename... Args> auto emplace(set<T>& c, Args&&... args) -> decltype(c.emplace(args...)) { c.emplace(args...); }
template <typename T> void umin(T &x, const T &y) { if (y < x) x = y; }
template <typename T> void umax(T &x, const T &y) { if (y > x) x = y; }
template <typename T> int sign(const T &x) {
  return x == 0 ? 0 : x > 0 ? 1 : -1;
}
template <typename T> T square(const T &x) { return x * x; }
// }}}
// {{{ IO
template <typename S, typename T>
istream& operator>>(istream& in, pair<S, T>& p) { return in >> p.first >> p.second; }
template <typename T> T read() { T x; cin >> x; return x; }
template <typename T, typename I = typename T::iterator>
void read(T &cnt) { for (auto& x : cnt) cin >> x; }
template <typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T>& p) {
  return out << "{" << p.first << ", " << p.second << "}";
}
template <typename T> struct show_container {
  const T &container;
  show_container(const T &container_) : container(container_) {}
};
template <typename T>
ostream &operator<<(ostream &o, const show_container<T> &thing) {
  bool first = true;
  o << "{";
  for (const auto &x : thing.container) {
    if (!first)
      o << ", ";
    first = false;
    o << x;
  }
  o << "}";
  return o;
}
template <typename T> show_container<T> show(const T &container) {
  return show_container<T>(container);
}

#define dprintf debug && printf
struct dout_ { } dout;
#ifdef ONLINE_JUDGE
template <typename T> dout_ &operator<<(dout_ &out, const T &thing) { return out; }
dout_ &operator<<(dout_ &out, ostream &(*thing)(ostream &)) { return out; }
#else
template <typename T> dout_ &operator<<(dout_ &out, const T &thing) { if (debug) cout << thing; return out; }
dout_ &operator<<(dout_ &out, ostream &(*thing)(ostream &)) { if (debug) cout << thing; return out; }
#endif

struct outboth {
  ostream &a;
  ostream &b;
  outboth(ostream &a_, ostream &b_) : a(a_), b(b_) {}
};
template <typename T> outboth &operator<<(outboth &both, const T &thing) {
  both.a << thing;
  both.b << thing;
  return both;
}
outboth &operator<<(outboth &both, ostream &(*thing)(ostream &)) {
  both.a << thing;
  both.b << thing;
  return both;
}
// }}}
// {{{ Solver

template <typename T>
void sort2(T& a, T& b) {
  if (a > b) swap(a, b);
}

void gentest() {
  std::mt19937_64 rng;
  int N = 100;
  Loop(t, 20) {
    cout << N << " " << N << " " << uniform_int_distribution<int>(1,N)(rng) << " " << uniform_int_distribution<int>(1,N)(rng) << endl;
    Loop(i, N) cout << (i ? " " : "") << uniform_int_distribution<int>(1,N)(rng);
    cout << endl;
  }
}

// ll eval(int t, const Vi& x, int A, int B) {
//   ll ans[2] = {0, 0}, init[2] = {min(A, B), max(A, B)}, first[2] = {-1, -1}, last[2] = {-1, -1};
//   for (int q : x) {
//     bool s = q > t;
//     if (first[s] == -1) first[s] = q;
//     if (last[s] != -1) ans[s] += abs(q - last[s]);
//     last[s] = q;
//   }
//   assert(first[0] == -1 || first[1] == -1 || first[0] <= first[1]);
//   // sort2(first[0], first[1]);
//   Loop(i,2) if (first[i] != -1) ans[i] += abs(init[i] - first[i]);
//   // dout << db(t) << db(ans[0]) << db(ans[1]) << ": " << (ans[0]-ans[1]) << ", " << (ans[0]+ans[1]) << endl;
//   return ans[0] + ans[1];
// };

// ll solve_correct(const Vi& x, int N, int A, int B) {

//   ll best = LLONG_MAX;
//   umin(best, eval(*std::min_element(All(x)), x, A, B));
//   umin(best, eval(*std::max_element(All(x)), x, A, B));
//   for (int i = 1; i <= N; ++i) {
//     umin(best, eval(i, x, A, B));
//   }
//   return best;
// }

struct cost {
  ll v = LLONG_MAX;
  cost() { }
  cost(ll v) : v(v) { }
  void operator+=(ll s) { if (v != LLONG_MAX) v += s; }
  void umin(ll u) { if (u < v) v = u; }
  cost operator+(ll s) const { return isinf() ? cost() : cost(v + s); }
  cost operator-(ll s) const { return isinf() ? cost() : cost(v - s); }
  bool operator<(cost o) const { return v < o.v; }
  bool isinf() const { return v == LLONG_MAX; }
  friend ostream& operator<<(ostream& out, cost c) { if (c.isinf()) return out << "#"; else return out << c.v; }
};

// {{{ Segment tree

struct Node {
  int low, high;
  cost value, vplus, vminus;
  ll deferred_sum = 0;
  unique_ptr<Node> left, right;
  Node(int low, int high) : low(low), high(high) {
    if (high - low >= 2) {
      left.reset(new Node(low, mid()));
      right.reset(new Node(mid(), high));
    }
  }

  bool isleaf() const { assert(high - low >= 1); return high == low + 1; }
  void operator+=(ll what) { deferred_sum += what; }
  int mid() const { return low + (high - low) / 2; }
  ll eval() { propagate(); return value.v; }
  void propagate() {
    value += deferred_sum;
    vplus += deferred_sum;
    vminus += deferred_sum;
    if (!isleaf()) {
      assert(left && right);
      left->deferred_sum += deferred_sum;
      right->deferred_sum += deferred_sum;
    }
    deferred_sum = 0;
  }

  void umin(int ix, ll what) {
    assert(what != LLONG_MAX);
    propagate();
    if (!Bounded(ix, low, high-1)) return;
    // dout << db(low) << db(mid()) << db(high) << db(ix) << db(what) << db(value) << endl;
    if (isleaf()) {
      value.umin(what);
      vplus = value + ix;
      vminus = value - ix;
    } else {
      (ix < mid() ? left : right)->umin(ix, what);
      value = min(left->eval(), right->eval());
      vplus = min(left->vplus, right->vplus);
      vminus = min(left->vminus, right->vminus);
    }
    // dout << db(low) << db(mid()) << db(high) << db(ix) << db(what) << db(value) << db(isleaf()) << endl;
    // check();
  }

  // void check() {
  //   propagate();
  //   assert(isleaf() || (value == min(left->value, right->value)));
  // }

  cost eval(int x) {
    propagate();
    if (isleaf()) return value + abs(x - low);
    return min(left->eval(x), right->eval(x));
  }
  cost evalPlus(int from, int to) {
    propagate();
    if (from >= high || to <= low) return cost();
    if (from <= low && to >= high) return vplus;
    return min(left->evalPlus(from, to), right->evalPlus(from, to));
  }
  cost evalMinus(int from, int to) {
    propagate();
    if (from >= high || to <= low) return cost();
    if (from <= low && to >= high) return vminus;
    return min(left->evalMinus(from, to), right->evalMinus(from, to));
  }

  void pp() {
    propagate();
    if (left) left->pp();
    if (value.isinf()) {
      dout << " #";
    } else {
      if (isleaf()) {
        dout << " " << low << "=" << value;
      } else {
        dout << " " << make_pair(low, high) << "=" << value << "/" << make_pair(vplus, vminus);
      }
    }
    if (right) right->pp();
  }
};

// }}}

#ifdef ONLINE_JUDGE
void solve(ostream& rout)
#else
void solve(outboth rout)
#endif
{
  // { gentest(); exit(0); }

  static int TC = 0;
  int N, Q, A, B; cin >> N >> Q >> A >> B; if (!cin) return;
  Vi x(Q); read(x);
  dout << "======================================================== " << ++TC << endl;
  dout << db(N) << db(Q) << db(A) << db(B) << endl << "x: " << show(x) << endl;

  Node root(0, N+1);
  root.umin(A, abs(B - x[0]));
  root.umin(B, abs(A - x[0]));
  for (int i = 1; i < Q; ++i) {
    // root.pp(); dout << endl;
    // ll u = root.eval(x[i]);
    cost u = min(root.evalPlus(x[i], N+1) - x[i], root.evalMinus(0, x[i]+1) + x[i]);
    // assert(u == root.eval(x[i]));
    root += abs(x[i] - x[i-1]);
    // root.umin(x[i-1], max(root.vplus - x[i], root.vminus + x[i]));
    root.umin(x[i-1], u.v);
    // root.pp(); dout << endl;
  }
  ll best = root.eval();

  // ll MAXCOST = LLONG_MAX / 4;
  // Vll dp(N+1, MAXCOST);
  // dp[A] = abs(B - x[0]);
  // dp[B] = abs(A - x[0]);
  // for (int i = 1; i < Q; ++i) {
  //   ll u = LLONG_MAX; Loop(j, N+1) umin(u, dp[j] + abs(x[i] - j));
  //   Loop(j, N+1) dp[j] = dp[j] == MAXCOST ? MAXCOST : dp[j] + abs(x[i] - x[i-1]);
  //   Loop(j, N+1) umin(dp[x[i-1]], u);
  // }
  // ll best = *std::min_element(All(dp));

  // ll MAXCOST = LLONG_MAX / 4;
  // Vll dp(N+1, MAXCOST), dp1(N+1);
  // dp[A] = abs(B - x[0]);
  // dp[B] = abs(A - x[0]);
  // for (int i = 1; i < Q; ++i) {
  //   dp.swap(dp1);
  //   Loop(j, N+1) dp[j] = dp1[j] == MAXCOST ? MAXCOST : dp1[j] + abs(x[i] - x[i-1]);
  //   Loop(j, N+1) umin(dp[x[i-1]], dp1[j] + abs(x[i] - j));
  // }
  // ll best = *std::min_element(All(dp));

  rout << best << endl;
  // exit(-1);
}

// }}}
  // {{{ Map solution (wrong)
  // map<int, int> sofar[2];
  // sofar[0][-1] = min(A, B);
  // sofar[1][-1] = max(A, B);
  // sofar[0][INT_MAX] = sofar[1][INT_MAX] = INT_MAX;
  // vector<Pii> elts; Loop(i, Q) push(elts, {i, x[i]});
  // sort(All(elts), [&](Pii a, Pii b) { return a.second < b.second; });

  // ll ans = 0;
  // for (Pii query : elts) {
  //   int time = query.first, where = query.second;
  //   auto p = sofar[1].upper_bound(time);
  //   assert(p != sofar[1].begin());
  //   --p;
  //   ans += abs(where - p->second);
  //   sofar[1].insert(p, query);
  // }

  // ll best = ans;
  // for (Pii query : elts) {
  //   int time = query.first, where = query.second;
  //   auto pAfter = sofar[0].upper_bound(time), q = sofar[1].find(time);
  //   assert(q != sofar[1].end() && pAfter != sofar[0].begin());
  //   auto pBefore = pAfter; --pBefore;
  //   auto qBefore = q, qAfter = q; --qBefore; ++qAfter;
  //   if (pAfter->first == INT_MAX) {
  //     ans += abs(where - pBefore->second);
  //   } else {
  //     ans += abs(pBefore->second - where) + abs(where - pAfter->second) - abs(pBefore->second - pAfter->second);
  //   }
  //   if (qAfter->first == INT_MAX) {
  //     ans += -abs(where - qBefore->second);
  //   } else {
  //     ans += abs(qBefore->second - qAfter->second) - abs(qBefore->second - where) - abs(qAfter->second - where);
  //   }
  //   dout << db(time) << db(where) << db(ans) << db(best) << endl;
  //   umin(best, ans);
  // }
  // }}}
// {{{ Main

int main() {
  // freopen("F.in", "r", stdin);
  // freopen("F.out", "w", stdout);
  std::ios::sync_with_stdio(false); cin.tie(nullptr);
  solve(cout);
  return 0;
}
// }}}

// clang-format off
// Local variables:
// compile-command: "make F && ./F"
// irony-additional-clang-options: ("-std=c++11")
// End:


Measured memory_bytes: 26112