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

using namespace std;

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