#include <stdio.h>
#include <stdlib.h>
void swap(long* a,long* b)
{
    int t = *a;
    *a = *b;
    *b = t;
}
int partition (long arr[],long low,long high)
{
    long pivot = arr[high];
    long i = (low - 1);

    for (long j = low; j <= high- 1; j++)
    {
        if (arr[j] < pivot)
        {
            i++;
            swap(&arr[i], &arr[j]);
        }
    }
    swap(&arr[i + 1], &arr[high]);
    return (i + 1);
}
void quickSort(long arr[],long low,long high)
{
    if (low < high)
    {
        long long pi = partition(arr, low, high);
        quickSort(arr, low, pi - 1);
        quickSort(arr, pi + 1, high);
    }
}
int main()
{
    long n,x;
    scanf("%d",&n);
    scanf("%d",&x);
    long a[n];
    for(long i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    quickSort(a, 0, n-1);
    if (x > a[n-1])
    {
        printf("%d",x-a[0]);
    }
    else if (x<a[0])
    {
        printf("%d",a[n-1]-x);
    }
    else if (a[n-1]-x<x-a[0])
    {
        printf("%d",(a[n-1]-x)*2+x-a[0]);
    }
    else if (a[n-1]-x>x-a[0])
    {
        printf("%d",(x-a[0])*2+a[n-1]-x);
    }
    else if(a[n-1]-x==x-a[0])
    {
        printf("%d",(x-a[0])*2+a[0]-x);
    }
}