#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl
#define int long long
#define double long double
using namespace std;
const int INF = 1LL<<35;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


class Seg{
public: 
  
  //遅延用の型  
  struct T{
    bool type; //0 - empty   , 1 - update
    int value;
    T():type(0),value(0){}
    T(bool type,int value):type(type),value(value){}
  };

  //比較可能な主データ型
  struct D{
    int value;
    D():value(0){} /*適切な値にする!!!!!!*/
    D(int value):value(value){}
    bool operator < (D a)const {return value < a.value;} //merge用
  };
  
  D INF = D(1LL<<55); /*!!!!!!!!!!!!!!!!!!!!!!!!*/

  int n;
  vector<D> dat;
  vector<T> td;
  int toMax; //0 -> RangeMin, 1 -> RangeMax
  
  Seg(){n=-1;}
  Seg(int n_,int toMax = 0){
    this->toMax = toMax;
    n=1;
    while(n<n_)n*=2;
    td.resize(2*n-1,T());
    dat.resize(2*n-1,D());
  }
  
  D merge(D a,D b){return min(a,b);}
  
  void delay(int k){
    if(td[k].type==0) return;
    int v = td[k].value;
    td[k].type = 0;
    td[k].value = 0;
    
    int l = k*2+1,r = k*2+2;
    dat[l].value += v; td[l].type = 1; td[l].value += v;
    dat[r].value += v; td[r].type = 1; td[r].value += v;
  }

  D update(int k,int x){
    td[k].type = 1;
    td[k].value += x;
    dat[k].value += x;
    return dat[k];
  }
  
  //[a,b)の値をx加算　add(a,b,x)
  D add(int a,int b,int x,bool flg=true,int k=0,int l=0,int r=-1){
    if(r==-1 && toMax) x *= -1; 
    if(r==-1) r=n, assert(a <= n && b <= n);
    if(r<=a||b<=l) return flg? dat[k]:INF;
    if(a<=l&&r<=b) return flg? update(k,x):dat[k];
    
    delay(k);
    D vl = add(a,b,x,flg,k*2+1,l,(l+r)/2);
    D vr = add(a,b,x,flg,k*2+2,(l+r)/2,r);
    if(flg) dat[k] = merge(vl,vr);
    return merge(vl,vr);
  }
  
  //[a,b)の最小値を得る　find(a,b);
  int find(int a,int b){
    D res = add(a,b,0,false);
    if(toMax) res.value *= -1; 
    return res.value;
  }
  void query(int i,int x){
    int val = find(i, i+1);
    if(val <= x) return;
    add(i, i+1, -val);
    assert(find(i, i+1) == 0);
    add(i, i+1, x);
  }
  
};

int solve(int n, int Q, int A,int B, vector<int> X){

  Seg S(n), T(n);
  S.add(0, n, INF);
  T.add(0, n, INF);

  
  S.query(A, A);
  T.query(A, n - A - 1);
  
  for(int i=1;i<=Q;i++){

    int s, t;
    {    //{ x -> Q[i], Q[i-1] -> Q[i-1];    
      int a = S.find(X[i], n) - X[i];
      int b = T.find(0, X[i]+1) - (n - X[i] - 1);
      s = min(a, b) + X[i-1];
      t = min(a, b) + (n - X[i-1] - 1);
    }
    
    
    { // {x -> x, Q[i-1] -> Q[i]}
      int d = abs(X[i] - X[i-1]);
      S.add(0, n, d);
      T.add(0, n, d);
    }
    
    S.query(X[i-1], s);
    T.query(X[i-1], t);
  }

  int ans = INF;
  for(int i=0;i<n;i++) Min(ans, S.find(i, i+1) - i);
  for(int i=0;i<n;i++) Min(ans, T.find(i, i+1) - (n - i - 1));

  return ans;
}

signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, Q, A, B; 
  cin>>n>>Q>>A>>B; A--,B--;
  vector<int> X(Q);
  cin>>X;
  for(int &x:X) x--;
  
  int a = INF;
  int b = INF;
  
  {
    vector<int> tmp  = X; tmp.insert(tmp.begin(), A);
    a = solve(n, Q, B, A, tmp);
  }
  {
    vector<int> tmp  = X; tmp.insert(tmp.begin(), B);
    b = solve(n, Q, A, B, tmp);
  }  
  int ans = min(a, b);
  cout<<ans<<endl; 
  
  return 0;
}


Measured memory_bytes: 33168