#include <iostream>
using namespace std;
int main()
{
    int n,x,p,k,t;
    cin>>n>>x;
    int a[n];
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int minn=a[0],maxx=a[0];
    for (int i=0;i<n;i++)
    {
        if (a[i]>maxx) maxx=a[i];
        if (a[i]<minn)  minn=a[i];
    }
        if (minn>x)
        {
            p=maxx-x;
            cout<<p;
        }
        if (maxx<x)
        {
            k=x-minn;
            cout<<k;
        }
        if (minn<x && maxx>x)
        {
            t=2*(x-minn)+ (maxx-x);
             cout<<t;
        }
    return 0;
}