#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    long long int x,n;
    cin>>n>>x;
    long long int maxx,minn;
    maxx=0;
    minn=9223372036854775807;
    long long int a;
    for (long long int i=0;i<n;i++){
         cin>>a;
         if (a>maxx){maxx=a;}
         if (a<minn){minn=a;}
         }
    cout<<min(abs(x-minn),abs(x-maxx))+(maxx-minn);
    return 0;
}