//Failure will never overtake me if my determination to succeed is strong enough
#include <bits/stdc++.h>

using namespace std;

long long a[1000006];

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

    long long n, x;
    cin >> n >> x;

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

    sort(a, a+n);

    cout << a[n-1]-a[0]+min(abs(x-a[0]), abs(x-a[n-1]));
}