/// created by ricpe13 ///
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    /////////////////////////////////


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

     int maximalan=a[1];
    for (int i=0;i<n;i++){
        if(maximalan<a[i])
        {
            maximalan=a[i];
        }
    }

    int minimalan=a[1];
    for (int i=0;i<n;i++){
        if(minimalan>a[i])
        {
            minimalan=a[i];
        }
    }

    if (x<minimalan){
        cout << abs(maximalan-x) << endl;
        return 0;
    }
    if (x>maximalan) {
        cout << abs(x-minimalan);
        return 0;
    }
    if (x>minimalan && x<maximalan){
        q=x-minimalan;
        w=maximalan-x;
        if (q<w){
            cout << abs(2*q+w) << endl;
            return 0;
        }
        if (q>w){
            cout << abs(2*w+q) << endl;
            return 0;
        }
        if (q==w){
            cout << abs(2*q+w) << endl;
            return 0;
        }
    }
    return 0;
}