#include <iostream>
#include <algorithm>

using namespace std;

long long n, x, a[1000001];

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> x;
    for( int i = 0; i < n; i++ )
    {
        cin >> a[i];
    }

    sort(a, a+n);

    if( a[0] < x && a[n-1] > x )
        cout << 2*min( abs(x-a[0]), abs(x-a[n-1]) ) + max( abs(x-a[0]), abs(x-a[n-1]) );
    else if( a[0] > x )
        cout << abs( a[n-1] - x );
    else
        cout << abs( a[0] - x );

    return 0;
}