#include <bits/stdc++.h>
using namespace std;
int n, x, niz[1000009];

int main () {

cin >> n >> x;

for (int i=1; i<=n; i++) {

    cin >> niz[i];
}

sort(niz+1, niz+1+n);

if (x<=niz[1])
    cout << niz[n]-x << endl;
else if (niz[1]<=x&&x<=niz[n]) {
    cout << min(x-niz[1], niz[n]-x)*2 + max(x-niz[1], niz[n]-x) << endl;
}
else if (x>=niz[n])
    cout << x-niz[1] << endl;




return 0;
}