#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,temp,mini,maxi,rez;
    cin >> n >> x;
    ll arr[n];
    for(ll i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    sort(arr,arr + n);
    mini = arr[0];
    maxi = arr[n-1];
    if(abs(x - mini) >= abs(x - maxi)) rez = abs(x - maxi);
    if(abs(x - mini) < abs(x - maxi)) rez = abs(x - mini);
    cout << rez + (maxi - mini);

    return 0;
}