#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int64 INF = 1LL << 60;

const int N = 2e5 + 10;
int a[N];

struct Node {
  int a, b;
  Node *left, *right;
  int64 dp, minv[2];
  int64 delta;
  void update(int64 delta) {
    this->delta += delta;
    dp += delta;
    minv[0] += delta;
    minv[1] += delta;
  }
  void pushdown() {
    if (!delta) return;
    left->update(delta);
    right->update(delta);
    delta = 0;
  }
  void pushup() {
    minv[0] = min(left->minv[0], right->minv[0]);
    minv[1] = min(left->minv[1], right->minv[1]);
  }
};

Node pool[N << 1], *last;

Node* build(int a, int b) {
  Node* cur = last++;
  cur->a = a;
  cur->b = b;
  cur->dp = cur->minv[0] = cur->minv[1] = INF;
  cur->delta = 0;
  if (a + 1 == b) return cur;
  cur->left = build(a, (a + b) / 2);
  cur->right = build((a + b) / 2, b);
  return cur;
}

int A, B;
int64 C;
void update(Node* cur) {
  if (cur->a + 1 == cur->b) {
    cur->dp = min(cur->dp, C);
    cur->minv[0] = cur->dp - cur->a;
    cur->minv[1] = cur->dp + cur->a;
    return;
  }
  cur->pushdown();
  if ((cur->a + cur->b) / 2 > A) update(cur->left);
  else update(cur->right);
  cur->pushup();
}

void insert(Node* cur) {
  if (cur->a >= A && cur->b <= B) {
    cur->update(C);
    return;
  }
  cur->pushdown();
  if ((cur->a + cur->b) / 2 > A) insert(cur->left);
  if ((cur->a + cur->b) / 2 < B) insert(cur->right);
  cur->pushup();
}

int64 query(Node* cur, int k) {
  if (cur->a >= A && cur->b <= B) {
    return cur->minv[k];
  }
  cur->pushdown();
  int64 ret = INF;
  if ((cur->a + cur->b) / 2 > A) ret = min(ret, query(cur->left, k));
  if ((cur->a + cur->b) / 2 < B) ret = min(ret, query(cur->right, k));
  return ret;
}

void print(Node* root, int n) {
  for (int i = 0; i < n; ++i) {
    A = i, B = i + 1;
    cout << i << " " << query(root, 0) + i << endl;
  }
  cout << "---" << endl;
}

int main() {
  int n, m, u, v;
  scanf("%d%d%d%d", &n, &m, &u, &v);
  --u; --v;
  for (int i = 0; i < m; ++i) {
    scanf("%d", &a[i]);
    --a[i];
  }
  last = pool;
  Node* root = build(0, n);
  A = v, C = abs(u - a[0]);
  update(root);
  A = u, C = abs(v - a[0]);
  update(root);
  for (int i = 1; i < m; ++i) {
    int64 cur = INF;
    A = 0, B = a[i];
    if (A < B) cur = min(cur, query(root, 0) + a[i]);
    A = a[i], B = n;
    if (A < B) cur = min(cur, query(root, 1) - a[i]);
    A = 0, B = n, C = abs(a[i - 1] - a[i]);
    insert(root);
    A = a[i - 1], C = cur;
    update(root);
  }
  int64 ret = INF;
  for (int i = 0; i < n; ++i) {
    A = i, B = A + 1;
    ret = min(ret, query(root, 0) + i);
  }
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 22912