#include <iostream>

using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;
    int a[n];
    for(int i = 0;i<n;i++)
    {
        cin >> a[i];
    }
    int max = a[0],min=a[0];
    for(int i = 1;i<n;i++)
    {
        if(a[i]>max) max = a[i];
        if(a[i]<min) min = a[i];
    }
    if(min<x&&max<x)
    {
        cout<<x-min;
    }
    if(min>x&&max>x)
    {
        cout<<max-x;
    }
    if(min<x&&max>x)
    {
        if(x-min>=max-x)
        {
            cout<<2*max-min-x;
        }
        else cout<<max+x-2*min;
    }
    return 0;
}