#include <iostream>
#include <algorithm>
using namespace std;
main ()
{
    long long int n,x,opt=0;
    cin>>n>>x;
    long long int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long long int minimum=min(x,*std::min_element(a,a+n));
    long long int maximum=max(x,*std::max_element(a,a+n));
    if(minimum==x || maximum==x)
    {
        opt=maximum-minimum;
    }
    else
    {
        if(x-minimum<maximum-x)
        {
            opt=2*(x-minimum)+(maximum-x);
        }
        else if(x-minimum>maximum-x)
        {
            opt=(x-minimum)+2*(maximum-x);
        }
        else
        {
            opt=2*(x-minimum)+(maximum-x);
        }
    }
    cout<<opt;
}