#include <stdio.h>
#include <stdlib.h>

void swap( int* a , int* b )
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

int partition ( int niz[] , int low , int high )
{
    int pivot = niz[high];
    int pi = (low - 1);

    for(int i=low;i<=high-1;i++)
    {

        if (niz[i] <= pivot)
        {
            pi++;
            swap(&niz[pi],&niz[i]);
        }
    }
    swap(&niz[pi+1],&niz[high]);
    return (pi+1);
}


void quickSort(int niz[], int low, int high)
{
    if (low < high)
    {
        int pi = partition(niz, low, high);

        quickSort(niz,low,pi-1);
        quickSort(niz,pi+1,high);
    }
}

int main()
{
    int n,x;

    scanf("%d",&n);
    scanf("%d",&x);

    int niz[n];

    for(int i=0;i<n;i++)
    {
        int v1;
        scanf("%d",&v1);

        niz[i] = v1;
    }

    quickSort(niz,0,n-1);

    int sum = 0;

    sum += niz[n-1] - niz[0];

    if(abs(niz[0]-x) <= abs(niz[n-1]-x))
    {
        sum+=abs(niz[0]-x);
    }
    else
    {
        sum+=abs(niz[n-1]-x);
    }

    printf("%d",sum);

    return 0;
}