#include <bits/stdc++.h>

using namespace std;

int main()
{
    long n,x;

    scanf("%ld%ld",&n,&x);
    long a[n];
    for (long i=0;i<n;i++)
        scanf("%ld",&a[i]);
    long s=0;
    long maks=a[0];
    long minn=a[0];


    for (long i=1;i<n;i++)
    if (a[i]>maks){maks=a[i];}

    for (long i=1;i<n;i++)
    if (a[i]<minn){minn=a[i];}

    if (abs(x-minn)<=abs(maks-x))
    {

    s=abs(x-minn);
    s=s+abs(maks-minn);
    printf("%ld ",s);
    }
    if (abs(x-minn)>abs(maks-x))
    {
        s=abs(maks-x);
        s=s+abs(maks-minn);
        printf("%ld ",s);
    }
}