#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;
  }
}

struct cost {
  ll v = LLONG_MAX;
  explicit cost() { }
  cost(ll v) : v(v) { }
  void operator+(cost o) const { min(*this, o); }
  void operator+=(cost o) { umin(o.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); }
  explicit operator ll() const { return v; }
  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();
  }
};

// }}}
// {{{ Sideways heap

/** A sideways heap, see Knuth 4A, 7.1.3, pp.164ff. */
struct SidewaysHeap {
  struct Entry {
    cost value, vplus, vminus;
    ll deferred = 0;
    Entry() { }
    Entry(cost value, cost vplus, cost vminus) : value(value), vplus(vplus), vminus(vminus) { }

    Entry combine(Entry o) const { return Entry(min(value, o.value), min(vplus, o.vplus), min(vminus, o.vminus)); }
    void umin(int ix, cost o) {
      assert(deferred == 0);
      if (o < value) {
        value = o;
        vplus = value + ix;
        vminus = value - ix;
      }
    }
    void operator+=(ll s) { value += s; vplus += s; vminus += s; }

    friend ostream& operator<<(ostream& out, Entry e) {
      return out << "{" << e.value << "," << e.vplus << "," << e.vminus << "," << e.deferred << "}";
    }
  };

  typedef uint32_t uu;
  uu n, m;
  vector<Entry> elts;
  SidewaysHeap(uu n_) : n(n_), m(roundup(2*n)), elts(m) {
    assert(sizeof(uu) == 4);
    dout << db(n) << db(m) << endl;
  }

  void pp(string label) const { dout << label << ":"; pp(root()); dout << endl; }
  void pp(uu x, int indent = 0) const {
    if (isleaf(x) && (x>>1) >= n) return;
    dout << "\n"; Loop(i, indent) dout << "  ";
    if (isleaf(x)) {
      dout << (x>>1) << "=" << elts[x];
    } else {
      dout << "(" << elts[x];
      pp(left(x), indent + 1);
      pp(right(x), indent + 1);
      dout << ")";
    }
  }

  Entry& operator[](int i) { assert(Bounded(i, 0, n-1)); return elts[ix(i)]; }
  void rebuild() {
    for (uu x = 2; x < m; x <<= 1)
      for (uu y = x; y < m; y += x << 1)
        update(y);
  }
  void uplus(ll what) {
    elts[root()].deferred += what;
    // pp("uplus");
  }
  void umin(int where, cost what) {
    assert(Bounded(where, 0, n-1));
    // pp("umin-begin");
    uu x = ix(where);
    for (uu y = root(); y != x; y = y > x ? left(y) : right(y))
      propagate(y);
    propagate(x);
    elts[x].umin(where, what);
    for (uu y = parent(x); y < m; y = parent(y)) update(y);
    // pp("umin");
  }
  Entry eval() { propagate(root()); return elts[root()]; }
  Entry eval(int from, int to) { return eval(root(), ix(from), ix(to-1)); }
  Entry eval(uu z, uu x, uu y) {
    assert(0 < x && x <= y && isleaf(x) && isleaf(y) && y < m);
    uu low = leftmost(z), high = rightmost(z);
    if (x > high || y < low) return Entry();
    propagate(z);
    if (x <= low && y >= high) return elts[z];
    assert(!isleaf(z));
    return eval(left(z), x, y).combine(eval(right(z), x, y));
  }

  void update(uu y) {
    if (isleaf(y)) return;
    propagateChildren(y);
    elts[y] = elts[left(y)].combine(elts[right(y)]);
  }
  void propagateChildren(uu x) { propagate(x); if (!isleaf(x)) { propagate(left(x)); propagate(right(x)); } }
  void propagate(uu x) {
    // for (uu y = parent(x); y < m; y = parent(y)) assert(elts[y].deferred == 0);
    if (elts[x].deferred == 0) return;
    elts[x].value += elts[x].deferred;
    elts[x].vplus += elts[x].deferred;
    elts[x].vminus += elts[x].deferred;
    if (!isleaf(x)) {
      elts[left(x)].deferred += elts[x].deferred;
      elts[right(x)].deferred += elts[x].deferred;
    }
    elts[x].deferred = 0;
  }

  uu root() const { return m >> 1; }
  static uu ix(int i) { return 2*i+1; }
  static uu leftmost(uu x) { return x - two(ruler(x)) + 1; }
  static uu rightmost(uu x) { return x + two(ruler(x)) - 1; }
  static uu roundup(uu n) { return uu((n&(n-1)) ? 2 : 1) << lg(n); }
  static bool isleaf(uu x) { return x&1; }
  static uu two(int i) { return uu(1) << i; }
  static int lg(uu x) { assert(x > 0); return 8*(sizeof(uu)) - 1 - __builtin_clz(x); }
  static int ruler(uu x) { assert(x > 0); return __builtin_ffs(x) - 1; }
  static uu parent(uu x) { assert(x > 0); uu y = x & -x; return (x - y) | (y << 1); }
  static uu left(uu x) { assert(!(x&1)); uu y = x & -x; return x - (y >> 1); }
  static uu right(uu x) { assert(!(x&1)); uu y = x & -x; return x + (y >> 1); }
  static uu ancestor(uu x, int h) { assert(h >= ruler(x)); return ((x >> h) | 1) << h; }
  static uu lca(uu x, uu y) { assert(x > 0 && y > 0); return y >= x ? ancestor(x, lg(y & -x)) : ancestor(y, lg(x & -y)); }

  static void test() {
    assert(sizeof(uu) == 4);
    assert(ruler(1) == 0);
    for (uint32_t x = 1; x <= 256; ++x) assert(ruler(x) == __builtin_ffs(x) - 1);
    for (int i = 1; i <= 32; ++i) {
      if (i&1)
        dout << setw(4) << i << setw(4) << parent(i) << endl;
      else
        dout << setw(4) << i << setw(4) << parent(i) << setw(4) << left(i) << setw(4) << right(i) << endl;
    }
    for (int i = 1; i <= 8; ++i) {
      for (int j = 1; j <= 8; ++j) {
        dout << db(i) << db(j) << db(lca(i, j)) << endl;
      }
    }
  }
};

// }}}

// void outputDeBruijnCycle(int m, int n) {
//   cout << "outputDeBruijnCycle m=" << m << ", n=" << n << endl;
//   assert(m >= 1 && n >= 1);
//   vector<int> a(n+1);
//   int j = 1;
//   a[0] = -1;
//   vector<int> deBruijn;
//   while (true) {
//     // cout << "j=" << j;
//     // for (int i = 1; i <= n; ++i) cout << " " << a[i];
//     // cout << endl;
//     if (n%j == 0) for (int i = 1; i <= j; ++i) deBruijn.push_back(a[i]);
//     for (j = n; a[j] == m-1; --j);
//     if (j == 0) break;
//     a[j]++;
//     for (int k = j+1; k <= n; ++k) a[k] = a[k-j];
//   }
//   cout << "de Bruijn cycle:\n";
//   for (int a : deBruijn) cout << " " << a;
//   cout << endl;
//   for (int i = 0; i < deBruijn.size(); ++i) {
//     for (int j = 0; j < n; ++j) cout << deBruijn[(i+j)%deBruijn.size()];
//     cout << endl;
//   }
// }

#ifdef ONLINE_JUDGE
void solve(ostream& rout)
#else
void solve(outboth rout)
#endif
{

  // for (unsigned x = 0; x <= 32; ++x) {
  //   dout << setw(3) << x << ": " << setw(4) << __builtin_ffs(x) << " " << setw(4) << __builtin_ctz(x) << " " << setw(4) << __builtin_clz(x) << endl;
  // }

  // outputDeBruijnCycle(2, 5);
  // uint32_t magic = 0x04653adf; // 0b00000100011001010011101011011111;
  // vector<uint32_t> ans;
  // vector<uint32_t> decode(32, -1);
  // for (int i = 0; i < 32; ++i) {
  //   push(ans, (((uint32_t(1) << i) * magic) >> 27));
  //   decode[(((uint32_t(1) << i) * magic) >> 27)] = i;
  // }
  // dout << show(decode) << endl;
  // dout << show(ans) << endl;
  // sort(All(ans));
  // dout << show(ans) << endl;
  // Loop(i, 32) if (ans[i] != i) dout << db(i) << endl;
  // exit(0);
  // SidewaysHeap::test();
  // exit(0);
  // { 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;

  SidewaysHeap heap(N+1);
  heap.umin(A, abs(B - x[0]));
  heap.umin(B, abs(A - x[0]));
  for (int i = 1; i < Q; ++i) {
    cost u = min(heap.eval(x[i], N+1).vplus - x[i], heap.eval(0, x[i]+1).vminus + x[i]);
    heap.uplus(abs(x[i] - x[i-1]));
    heap.umin(x[i-1], u.v);
  }
  ll best = heap.eval().value.v;

  // 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);
}

// }}}
// {{{ 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: 17408