#include<bits/stdc++.h>
using namespace std;
int N,M,x,a,b;
int main(){
    cin>>N>>M;
    cin>>x;
    a=min(x,M);
    b=max(x,M);
    if(N==1)cout<<abs(M-x)<<endl;
    else {
        for(int i=2; i<=N; i++){cin>>x;a=min(a,x);b=max(b,x);}
        //cout<<a<<" "<<b<<endl;
        cout<<min(abs(M-a),abs(M-b))*2+max(abs(M-a),abs(M-b));
    }
    return 0;
}