#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,rez;

    cin >> n >> x;

    ll mini = x,maxi = x;

    for(ll i = 0; i < n; ++i) {
        cin >> temp;
        if(temp < mini) mini = temp;
        if(temp > maxi) maxi = temp;
    }
    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;
}