#include <bits/stdc++.h>

using namespace std;

int n;
long long x, maxx, minn;

int main()
{
    cin>>n>>x;
    cin>>minn;
    maxx=minn;
    for (int i=0; i<n-1; i++)
    {
        long long poz;
        cin>>poz;
        maxx=max(maxx, poz);
        minn=min(minn, poz);
    }

    if (maxx<=x)
        cout<<x-minn;
    else if (minn>=x)
        cout<<maxx-x;
    else
        cout<<min(2*(x-minn)+maxx-x, 2*(maxx-x)+x-minn);
}