#include<bits/stdc++.h>
using namespace std;
int n,x,a[1000005];
int main()
{
    scanf("%d %d",&n,&x);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
    if(a[1]<=x and a[n]>=x)
    {
        cout<<abs(x-a[1])+abs(x-a[n])+min(abs(x-a[1]),abs(x-a[n]))<<endl;
        return 0;
    }
    if(a[1]<=x and a[n]<=x)
    {
        cout<<abs(x-min(a[1],a[n]))<<endl;
        return 0;
    }
    else
    {
        cout<<abs(x-max(a[1],a[n]))<<endl;
        return 0;
    }
    return 0;
}