#include <iostream>

using namespace std;

int main() {
    long long int x, mini, maxi, br;
    int n;
    cin >> n >> x;
    
    cin >> br;
    mini = br;
    maxi = br;
    
    for(int i; i < n - 1; i++){
        cin >> br;
        if(br > maxi)
            maxi = br;
        else if(br < mini)
        {
            mini = br;
        }
    }
    
    if(mini >= x)
    {
        cout << maxi - x;
    }
    else if(maxi <= x)
    {
        cout << x - mini;
    }
    else
    {
        long long int levi, desni;
        levi = x - mini;
        desni = maxi - x;
        if(levi > desni)
        {
            cout << desni * 2 + levi;
        }
        else
        {
            cout << levi * 2 + desni;
        }
    }
    
    cout << "\n" << "maxi = " << maxi << "\nmini = " << mini;
}