#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x,a,mini=100000000,maxi=-100000000;
    cin>>n>>x;
    for(int i=0; i<n; ++i) {
        cin>>a;
        mini=min(mini,a);
        maxi=max(maxi,a);
    }
    if(x<=mini) {
        cout<<maxi-x;
    }
    else if(x>=maxi) {
        cout<<x-mini;
    }
    else {
        int x1,x2;
        x1=x-mini;
        x2=maxi-x;
        if(x2<x1) cout<<2*x2+x1;
        else cout<<2*x1+x2;
    }
    return 0;
}