#include <bits/stdc++.h>

using namespace std;
long long int a[1000010];
int main()
{
    long long int n,x,nmin,nmax;
    cin >> n >> x;
    for (int i=0;i<n;i++){
        cin >> a[i];if (i==0) {nmax=a[i];nmin=a[i];}
        if (a[i]>nmax) nmax=a[i];
        if (a[i]<nmin) nmin=a[i];
    }
    if (nmin>x) cout << nmax-x;
    else if (nmax<x) cout << x-nmin;
    else if (abs(x-nmin)<=abs(nmax-x)) cout << nmax-nmin+abs(x-nmin);
    else cout << nmax-nmin+abs(nmax-x);
    return 0;
}