#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MOD = 1e9+7;
const int N = 1e6+5;
const ll INF = 1e9;

int n;
ll a[N],x;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>x;

    ll mn=INF;
    ll mx=-INF;

    for(int i=1;i<=n;i++){
        cin>>a[i];
        mn=min(mn,a[i]);
        mx=max(mx,a[i]);
    }

    if(x>=mx){
        cout<<abs(mn-x);
    }else if(x<=mn){
        cout<<abs(mx-x);
    }else{
        cout<<min(abs(x-mn),abs(x-mx))+abs(mn-mx);
    }

    return 0;
}