#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;
    int a[n], i, minimum = 0, maximum = 0, br = 0;
    for(i=0;i<n;i++)
        cin >> a[i];

    minimum = a[0];
    for(i=0;i<n;i++)
        if(minimum > a[i])
            minimum = a[i];
    maximum = a[0];
    for(i=0;i<n;i++)
        if(maximum < a[i])
            maximum = a[i];

    if(minimum > x && maximum > x)
        br = abs(x - maximum);
    else if(minimum < x && maximum > x && abs(x - maximum) > abs(minimum - x))
        br = abs(minimum - x) * 2 + abs(x - maximum);
    else if(minimum < x && maximum > x && abs(x - maximum) < abs(minimum - x))
        br = abs(x - maximum) * 2 + abs(minimum - x);
    else if(minimum < x && maximum > x && abs(x - maximum) == abs(minimum - x))
        br = abs(x - maximum) * 3;
    else if(minimum < x && maximum < x)
        br = abs(minimum - x);

    cout << br;

}