#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
template <typename Monoid>
struct RMQandRAQ {
  RMQandRAQ(int sz_, const Monoid &UNITY_, const Monoid &DEFAULT_ = 0) : UNITY(UNITY_), DEFAULT(DEFAULT_) {
    init(sz_);
    dat.assign((sz << 1) - 1, DEFAULT);
  }

  RMQandRAQ(const vector<Monoid> &seq, const Monoid &UNITY_, const Monoid &DEFAULT_ = 0) : UNITY(UNITY_), DEFAULT(DEFAULT_) {
    int seq_sz = seq.size();
    init(seq_sz);
    dat.resize((sz << 1) - 1);
    REP(i, seq_sz) dat[sz - 1 + i] = seq[i];
    for (int i = sz - 2; i >= 0; --i) dat[i] = min(dat[(i << 1) + 1], dat[(i << 1) + 2]);
  }

  void add(int a, int b, Monoid value) { add(a, b, value, 0, 0, sz); }

  Monoid query(int a, int b) { return query(a, b, 0, 0, sz); }

  int find(int a, int b, Monoid value) { return find(a, b, value, 0, 0, sz); }

private:
  int sz = 1;
  const Monoid UNITY, DEFAULT;
  vector<Monoid> dat, lazy;

  void init(int sz_) {
    while (sz < sz_) sz <<= 1;
    lazy.assign((sz << 1) - 1, DEFAULT);
  }

  inline void evaluate(int node) {
    if (lazy[node] != DEFAULT) {
      dat[node] += lazy[node];
      if (node < sz - 1) {
        lazy[(node << 1) + 1] += lazy[node];
        lazy[(node << 1) + 2] += lazy[node];
      }
      lazy[node] = DEFAULT;
    }
  }

  void add(int a, int b, Monoid value, int node, int left, int right) {
    evaluate(node);
    if (right <= a || b <= left) return;
    if (a <= left && right <= b) {
      lazy[node] += value;
      evaluate(node);
    } else {
      add(a, b, value, (node << 1) + 1, left, (left + right) >> 1);
      add(a, b, value, (node << 1) + 2, (left + right) >> 1, right);
      dat[node] = min(dat[(node << 1) + 1], dat[(node << 1) + 2]);
    }
  }

  Monoid query(int a, int b, int node, int left, int right) {
    evaluate(node);
    if (right <= a || b <= left) return UNITY;
    if (a <= left && right <= b) return dat[node];
    return min(query(a, b, (node << 1) + 1, left, (left + right) >> 1), query(a, b, (node << 1) + 2, (left + right) >> 1, right));
  }

  int find(int a, int b, Monoid value, int node, int left, int right) {
    evaluate(node);
    if (dat[node] > value || right <= a || b <= left) return -1;
    if (right - left == 1) return node - (sz - 1);
    int res_l = find(a, b, value, (node << 1) + 1, left, (left + right) >> 1);
    if (res_l != -1) return res_l;
    return find(a, b, value, (node << 1) + 2, (left + right) >> 1, right);
  }
};

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, q, a, b; cin >> n >> q >> a >> b;
  vector<long long> init_l(n + 1, LINF / 2), init_r(n + 1, LINF / 2);
  init_l[a] = -a;
  init_r[a] = a;
  RMQandRAQ<long long> dp_l(init_l, LINF), dp_r(init_r, LINF);
  vector<int> x(q + 1); FOR(i, 1, q + 1) cin >> x[i];
  x[0] = b;
  FOR(i, 1, q + 1) {
    long long dp = min(dp_l.query(1, x[i]) + x[i], dp_r.query(x[i], n + 1) - x[i]);
    dp_l.add(x[i - 1], x[i - 1] + 1, dp - x[i - 1] - dp_l.query(x[i - 1], x[i - 1] + 1));
    dp_r.add(x[i - 1], x[i - 1] + 1, dp + x[i - 1] - dp_r.query(x[i - 1], x[i - 1] + 1));
    dp_l.add(1, n + 1, abs(x[i] - x[i - 1]));
    dp_l.add(x[i - 1], x[i - 1] + 1, -abs(x[i] - x[i - 1]));
    dp_r.add(1, n + 1, abs(x[i] - x[i - 1]));
    dp_r.add(x[i - 1], x[i - 1] + 1, -abs(x[i] - x[i - 1]));
    // cout << x[i] << " | ";
    // FOR(i, 1, n + 1) {
    //   long long tmp = dp_l.query(i, i + 1) + i;
    //   cout << (tmp > LINF / 2 ? -1 : tmp) << ' ';
    // }
    // cout << '\n';
  }
  long long ans = LINF;
  FOR(i, 1, n + 1) {
    ans = min(ans, dp_l.query(i, i + 1) + i);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 20608