#include <iostream>
#include <algorithm>
using namespace std;
main ()
{
    long long int N;
    long long int X;
    long long int resenje = 0;
    cin>>N>>X;
    long long int a[N];
    for(int i=0;i<N;i++)
    {
        cin>>a[i];
    }
    long long int Min=min(X,*std::min_element(a,a+N));
    long long int Max=max(X,*std::max_element(a,a+N));
    if(Min==X || Max==X)
    {
        resenje=Max-Min;
    }
    else
    {
        if(X-Min<Max-X)
        {
            resenje=(Max-X)+2*(X-Min);
        }
        else if(X-Min>Max-X)
        {
            resenje=(X-Min)+2*(Max-X);
        }
        else
        {
            resenje=(Max-X)+2*(X-Min);
        }
    }
    cout<<resenje;
}