#include <bits/stdc++.h>
using namespace std;
int n,x,a[1000010],lm,dm,b,c;
int main ()
{
    cin>>n>>x;
    lm=x;
    dm=x;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]<=x and a[i]<=lm)
        {
            lm=a[i];
        }
        if(a[i]>=x and a[i]>=dm)
        {
            dm=a[i];
        }
    }
    if(dm-x>=x-lm)
    {
        cout<<(x-lm)*2+dm-x<<endl;
    }
    else cout<<(dm-x)*2+x-lm<<endl;
return 0;
}