#include <bits/stdc++.h>
using namespace std;
long long n, x;
int main() {
cin >> n >> x;
int a[n+5];
double y=-100000000;
for(int i=1; i<=n; i++) {
    cin >> a[i];
    if(y<a[i]) y=a[i];
} if(n>=2){
    double j=1000000000;
for(int i=1; i<=n; i++) {
    if(j>a[i]) j=a[i];
}
if(x>y) cout << x-j << endl;
else if(x<j) cout << y-x << endl;
else if(x>j && x<y) cout << x-j+y-j << endl;
}
else if(x>y) cout << x-y << endl;
     else cout << y-x << endl;
return 0;
}