#include <bits/stdc++.h>

using namespace std;


int main()
{
    long n,x,res,minimum = numeric_limits<long>::max(),maximum = numeric_limits<long>::min();
    scanf("%ld %ld",&n,&x);

    for(int i = 0;i<n;i++)
    {
        long pom;
        scanf("%ld",&pom);
        if(pom > maximum)
        {
            maximum = pom;
        }
        if(pom < minimum)
        {
            minimum = pom;
        }
    }

    // Kuca na krajevima
    if(x < minimum)
    {
        res = maximum - x;
    }
    else if(x > maximum)
    {
        res = x - minimum;
    }

    // Kuca u sredini
    else if(abs(x-minimum) < abs(x-maximum))
    {
        res = 2*abs(x-minimum) + abs(x-maximum);
    }
    else
    {
        res = 2*abs(x-maximum) + abs(x-minimum);
    }
    printf("%ld",res);
    return 0;
}