#include<bits/stdc++.h>
using namespace std;
# ifdef DEB
# define debug(...) fprintf(stderr, __VA_ARGS__)
# else
# define debug(...)
#endif
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LL long long
#define LD long double
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define pb pop_back
#define VI vector<int> 
#define VPI vector<PII> 
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define ALL(x) (x).begin(), (x).end()
#define siz(V) ((int)V.size())
const int M = 1024 * 256;
const LL inf = 1e12;

struct node
{
  LL ad, mi, i;
};

node D[3][2 * M];
LL res = inf;
int T[M];
int n, q, A, B;

LL get(int ind)
{
  ind += M;
  LL r = D[0][ind].ad;
  while (ind > 1)
  {
    ind /= 2;
    r += D[0][ind].ad;
  }
  return r;
}

void fix(int v, int ind)
{
  if (D[ind][2 * v].mi + D[ind][2 * v].ad < D[ind][2 * v + 1].mi + D[ind][2 * v + 1].ad)
  {
    D[ind][v].mi = D[ind][2 * v].mi + D[ind][2 * v].ad;
    D[ind][v].i = D[ind][2 * v].i;
  }
  else
  {
    D[ind][v].mi = D[ind][2 * v + 1].mi + D[ind][2 * v + 1].ad;
    D[ind][v].i = D[ind][2 * v + 1].i;
  }
}

void prop(int v, int ind)
{
  D[ind][2 * v].ad += D[ind][v].ad;
  D[ind][2 * v + 1].ad += D[ind][v].ad;
  D[ind][v].ad = 0;
}

void sett(int v, int vp, int vk, int x, LL val, int ind)
{
  if (vp == vk)
  {
    D[ind][v].i = x;
    D[ind][v].ad = val;
    return;
  }
  int mid = (vp + vk) / 2;
  prop(v, ind);
  if (x <= mid)
  {
    sett(2 * v, vp, mid, x, val, ind);
  }
  else
  {
    sett(2 * v + 1, mid + 1, vk, x, val, ind);
  }
  fix(v, ind);
}

void seet(int ind, LL val)
{
  sett(1, 0, M - 1, ind, val, 0);
  sett(1, 0, M - 1, ind, val - ind, 1);
  sett(1, 0, M - 1, ind, val + ind, 2);
}

pair<int, LL> mini(int v, int vp, int vk, int p, int k, int ind)
{
  if (vp > k || vk < p)
  {
    return MP(-1, -1);
  }
  if (vp >= p && vk <= k)
  {
    return MP(D[ind][v].i, D[ind][v].mi + D[ind][v].ad);
  }
  int mid = (vp + vk) / 2;
  prop(v, ind);
  pair<int, LL> r1 = mini(2 * v, vp, mid, p, k, ind);
  pair<int, LL> r2 = mini(2 * v + 1, mid + 1, vk, p, k, ind);
  fix(v, ind);
  if (r1.F == -1 || (r2.F != -1 && r1.S > r2.S))
  {
    return r2;
  }
  return r1;
}

int main()
{
  //ios_base::sync_with_stdio(0);
  scanf("%d%d%d%d", &n, &q, &A, &B);
  T[0] = B;
  for (int i = 1; i <= q; i++)
  {
    scanf("%d", T + i);
  }
  for (int i = 0; i < M; i++)
  {
    seet(i, inf);
  }
  seet(A, 0);
  /*for (int j = 1; j <= n; j++)
  {
    printf("%lld ", get(j));
  }
  printf("\n");*/
  for (int i = 1; i <= q; i++)
  {
    int ind = T[i - 1];
    int lef = mini(1, 0, M - 1, 0, T[i], 1).F, rig = mini(1, 0, M - 1, T[i], M - 1, 2).F;
    LL dplef = get(lef) + abs(T[i] - lef), dprig = get(rig) + abs(rig - T[i]);
    //debug("%d: %d %d %d\n", i, ind, lef, rig);
    for (int j = 0; j < 3; j++)
    {
      D[j][1].ad += llabs(T[i] - T[i - 1]);
    }
    seet(ind, min(get(ind), min(dplef, dprig)));
    /*for (int j = 1; j <= n; j++)
    {
      printf("%lld ", get(j));
    }
    printf("\n");*/
  }
  for (int i = 1; i <= n; i++)
  {
    res = min(res, get(i));
  }
  printf("%lld\n", res);
  return 0;
}

Measured memory_bytes: 37888