#include <bits/stdc++.h>
#define ll long long
#define si short int
using namespace std;

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n,x;
    cin>>n>>x;
    ll mini=INT_MAX,maxi=INT_MIN;

    for(ll i=0;i<n;i++)
    {
        ll a;
        cin>>a;
        mini=min(a,mini);
        maxi=max(a,maxi);
    }
    if(x>=mini && x<=maxi)
        cout<<abs(x-mini)+abs(maxi-mini);
    else if(x>maxi)
        cout<<abs(x-mini);
    else
        cout<<abs(maxi-x);
}