#include <bits/stdc++.h>
using namespace std;
int main(){
long long neiNum;
long long leftEnd= 9000000000;
long long rightEnd =  -9000000000;
long long cord;
long long mx = 2000000000;
long long sol = 0;
scanf("%lld",&neiNum);
scanf("%lld",&cord);
long long curr;
for(int i = 0; i < neiNum; ++i){
    scanf("%lld",&curr);
    if((curr<leftEnd) && (curr<cord))
        leftEnd = curr;
    if((curr>rightEnd) && (curr>cord))
        rightEnd = curr;
}


if(leftEnd > mx) sol =abs(rightEnd-cord);
else if(rightEnd*(-1) > mx) sol =abs(leftEnd-cord);
else if(abs(cord-leftEnd) > abs(rightEnd-cord)){
    sol = 2*abs(rightEnd-cord)+abs(cord-leftEnd);

}else{
    sol = abs(rightEnd-cord)+2*abs(cord-leftEnd);
}
printf("%lld",sol);

return 0;
}