#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    long int n,x,t=0,k=0,c,c1;
    cin>>n>>x;
    long int  a[n];
    for (long int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    t=a[0];
    k=a[0];
    for (long int i=1;i<n;i++)
    {
        if (t<a[i])
            t=a[i];
        if (k>a[i])
            k=a[i];
    }
    if ((x==k) || (x==t))
    {
        cout<<t-k;
    }
    if (x>t)
    {
        cout<<x-k;
    }
    if (x<k)
    {
        cout<<(t-x);
    }
    if ((x>k) && (x<t))
    {
        c=min((t-x),(x-k));
        c1=max((t-x),(x-k));
        cout<<2*c+c1;
    }
    return 0;
}