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

int main ()
{
    long n;
    long long x, t, Min, Max;
    scanf ("%ld%lld", &n, &x);
    scanf ("%lld", &t);
    Min = t;
    Max = t;

    for (long i=1; i<n; i++)
    {
        scanf ("%lld", &t);
        if (t<Min)
            Min = t;
        if (t>Max)
            Max = t;
    }

    if (Min<x && x<Max)
    {
        if (x-Min<=Max-x)
            printf ("%lld", Max-Min+x-Min);
        else
            printf ("%lld", Max-Min+Max-x);
    }
    else if (x<=Min)
        printf ("%lld", Max-x);
    else
        printf ("%lld", x-Min);

    return 0;
}