#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,x,p;
    vector <int> A;

    cin >> n >> x;
    for ( int i = 0; i < n; i++ )
    {
        cin >> p;
        A.push_back(p);
    }
    sort( A.begin(), A.end() );

    if ( x <= A[0] )
    {
        cout << A[n-1]-x;
    }
    else if ( x >= A[n-1] )
    {
        cout << x-A[0];
    }
    else
    {
        if ( x-A[0] < A[n-1]-x )
        {
            cout << A[n-1]-A[0]+(x-A[0]);
        }
        else
        {
            cout << A[n-1]-A[0]+(A[n-1]-x);
        }
    }
    return 0;
}