#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

struct StarrySkyTree {
  vector<ll> seg, lazy;
  int size;
  StarrySkyTree() {}
  StarrySkyTree(int n) {
    init(n);
  }
  void init(int n) {
    size = 1;
    while (size < n) size *= 2;
    seg.resize(size * 2);
    lazy.resize(size * 2);
    rep(i,size*2)lazy[i]=0;
    rep(i,size*2)seg[i]=INF;
  }
  void update(ll k,ll v){
    k+=size-1;
    seg[k]=v;
    while(k>0){
      k=(k-1)/2;
      seg[k]=min(seg[k*2+1],seg[k*2+2]);
    }
  }
  void push(int k, int l, int r) {
    seg[k] += lazy[k];
    if (r - l > 1) {
      lazy[k * 2 + 1] += lazy[k];
      lazy[k * 2 + 2] += lazy[k];
    }
    lazy[k] = 0;
  }
  void add(int a, int b, ll v, int k, int l, int r) {
    push(k, l, r);
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      lazy[k] += v;
      push(k, l, r);
    } else {
      add(a, b, v, k * 2 + 1, l, (l + r) / 2);
      add(a, b, v, k * 2 + 2, (l + r) / 2, r);
      seg[k] = min(seg[k * 2 + 1], seg[k * 2 + 2]);
    }
  }
  void add(int a, int b, ll v) {
    add(a, b, v, 0, 0, size);
  }
  ll query(int a, int b, int k, int l, int r) {
    push(k, l, r);
    if (r <= a || b <= l) return INF*100;
    if (a <= l && r <= b) return seg[k];
    ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  ll query(int a, int b) {
    return query(a, b, 0, 0, size);
  }
};

ll n,q,a,b;
ll x[200002];
StarrySkyTree dp,pos,neg;

int main(){
  cin>>n>>q>>a>>b;
  a--; b--;
  x[0]=b;
  repl(i,1,q+1){
    cin>>x[i];
    x[i]--;
  }
  dp.init(n); pos.init(n); neg.init(n);
  rep(i,n){
    dp.update(i,INF); pos.update(i,INF); neg.update(i,INF);
  }
  dp.update(a,0); pos.update(a,+a); neg.update(a,-a);
  repl(i,1,q+1){
    //rep(i,n)cout<<dp.query(i,i+1)<<" ";
    //cout<<endl;
    ll l=neg.query(0,x[i])+x[i];
    ll r=pos.query(x[i]+1,n)-x[i];
    ll m=dp.query(x[i],x[i]+1);

    //dbg(l); dbg(r); dbg(m);
    m=min(m,min(l,r));

    //dbg(m); dbg(dp.query(x[i-1],x[i-1]+1)); dbg(m-dp.query(x[i-1],x[i-1]+1));
    dp.add(x[i-1],x[i-1]+1,m-dp.query(x[i-1],x[i-1]+1));
    neg.add(x[i-1],x[i-1]+1,m-neg.query(x[i-1],x[i-1]+1)-x[i-1]);
    pos.add(x[i-1],x[i-1]+1,m-pos.query(x[i-1],x[i-1]+1)+x[i-1]);
    //dbg(m); dbg(dp.query(x[i-1],x[i-1]+1));
    //rep(i,n)cout<<dp.query(i,i+1)<<" ";
    //cout<<endl;

    dp.add(0,x[i-1],abs(x[i]-x[i-1])); dp.add(x[i-1]+1,n,abs(x[i]-x[i-1]));
    neg.add(0,x[i-1],abs(x[i]-x[i-1])); neg.add(x[i-1]+1,n,abs(x[i]-x[i-1]));
    pos.add(0,x[i-1],abs(x[i]-x[i-1])); pos.add(x[i-1]+1,n,abs(x[i]-x[i-1]));
  }
  //rep(i,n)cout<<dp.query(i,i+1)<<" ";
  //cout<<endl;
  cout<<dp.query(0,n)<<endl;
	return 0;
}


Measured memory_bytes: 26368