#include <bits/stdc++.h>
using namespace std;
namespace IO
{
    const int __S=(1<<20)+5;char __buf[__S],*__H,*__T;
    inline char getc()
    {
        if(__H==__T) __T=(__H=__buf)+fread(__buf,1,__S,stdin);
        if(__H==__T) return -1;return *__H++;
    }
    template <class __I>inline void read(__I &__x)
    {
        __x=0;int __fg=1;char __c=getc();
        while(!isdigit(__c)&&__c!='-') __c=getc();
        if(__c=='-') __fg=-1,__c=getc();
        while(isdigit(__c)) __x=__x*10+__c-'0',__c=getc();
        __x*=__fg;
    }
    inline void readd(double &__x)
    {
        __x=0;double __fg=1.0;char __c=getc();
        while(!isdigit(__c)&&__c!='-') __c=getc();
        if(__c=='-') __fg=-1.0,__c=getc();
        while(isdigit(__c)) __x=__x*10.0+__c-'0',__c=getc();
        if(__c!='.'){__x=__x*__fg;return;}else while(!isdigit(__c)) __c=getc();
        double __t=1e-1;while(isdigit(__c)) __x=__x+1.0*(__c-'0')*__t,__t=__t*0.1,__c=getc();
        __x=__x*__fg;
    }
    inline void reads(char *__s,int __x)
    {
        char __c=getc();int __tot=__x-1;
        while(__c<'!'||__c>'~') __c=getc();
        while(__c>='!'&&__c<='~') __s[++__tot]=__c,__c=getc();
        __s[++__tot]='\0';
    }
    char __obuf[__S],*__oS=__obuf,*__oT=__oS+__S-1,__c,__qu[55];int __qr;
    inline void flush(){fwrite(__obuf,1,__oS-__obuf,stdout);__oS=__obuf;}
    inline void putc(char __x){*__oS++ =__x;if(__oS==__oT) flush();}
    template <class __I>inline void print(__I __x)
    {
        if(!__x) putc('0');
        if(__x<0) putc('-'),__x=-__x;
        while(__x) __qu[++__qr]=__x%10+'0',__x/=10;
        while(__qr) putc(__qu[__qr--]);
    }
    inline void prints(const char *__s,const int __x)
    {
        int __len=strlen(__s+__x);
        for(int __i=__x;__i<__len+__x;__i++) putc(__s[__i]);
    }
    inline void printd(double __x,int __d)
    {
        long long __t=(long long)floor(__x);print(__t);putc('.');__x-=(double)__t;
        while(__d--)
        {
            double __y=__x*10.0;__x*=10.0;
            int __c=(int)floor(__y);
            putc(__c+'0');__x-=floor(__y);
        }
    }
    inline void el(){putc('\n');}inline void sp(){putc(' ');}
}using namespace IO;
#define ll long long
ll f[800005],g[800005],h[800005],z[800005];int n,m,a,b,p[200005];
void add(int x,ll v){f[x]+=v;g[x]+=v;h[x]+=v;z[x]+=v;}
void dn(int x){add(x*2,z[x]);add(x*2+1,z[x]);z[x]=0;}
void build(int x,int l,int r)
{
    f[x]=g[x]=h[x]=1e18;if(l==r) return;
    int mid=(l+r)>>1;build(x*2,l,mid);build(x*2+1,mid+1,r);
}
void upd(int x,int l,int r,int p,ll v)
{
    if(l==r){if(v<f[x]) f[x]=v,g[x]=v-l,h[x]=v+l;return;}dn(x);
    int mid=(l+r)>>1;p<=mid?upd(x*2,l,mid,p,v):upd(x*2+1,mid+1,r,p,v);
    f[x]=min(f[x*2],f[x*2+1]);g[x]=min(g[x*2],g[x*2+1]);h[x]=min(h[x*2],h[x*2+1]);
}
ll que(int x,int l,int r,int b,int e,int o)
{
    if(b<=l&&r<=e) return o?h[x]:g[x];dn(x);int mid=(l+r)>>1;
    return min(b<=mid?que(x*2,l,mid,b,e,o):1e18,e>mid?que(x*2+1,mid+1,r,b,e,o):1e18);
}
int main()
{
    read(n);read(m);read(a);read(b);p[0]=b;build(1,1,n);upd(1,1,n,a,0);
    for(int i=1;i<=m;i++) read(p[i]);
    for(int i=1;i<=m;i++)
    {
        ll mn=min(que(1,1,n,1,p[i],0)+p[i],que(1,1,n,p[i]+1,n,1)-p[i]);
        add(1,abs(p[i]-p[i-1]));upd(1,1,n,p[i-1],mn);
    }
    printf("%lld\n",f[1]);
}

Measured memory_bytes: 28032