#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    int n,x,a[100],i;
    scanf("%d %d", &n, &x);
    for (i=0; i<n; i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    if (x<=a[0])
        printf("%d",a[n-1]-x);
    else if (x>=a[n-1])
        printf("%d",x-a[0]);
    else
        if (x-a[0] < a[n-1]-x)
            printf("%d",x-a[0]+a[n-1]-a[0]);
        else
            printf("%d",a[n-1]-x+a[n-1]-a[0]);
    return 0;
}