#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    int n, x;
    cin>>n>>x;
    if(n==0)cout<<0;
    else if(n==1){
        int help1;
        cin>>help;
        if(help==x)cout<<0;
        else if(help<x)cout<<x-help;
        else cout<<help-x;
    }
    else{
    int komsije [n];
    cin>>komsije[0];
    int levi=komsije[0];
    int desni=komsije[0];
    for(int i=1;i<n;i++)
    {
        cin>>komsije[i];
        if(komsije[i]>desni)desni=komsije[i];
        else if(komsije[i]<levi)levi=komsije[i];
    }
    if(levi>=x)cout<<desni-x;
    else if(desni<=x)cout<<x-levi;
    else if(x-levi<desni-x)cout<<x-levi+desni-levi;
    else cout<<desni-x+desni-levi;
    }
}