#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    long n, x;
    std::cin >> n >> x;

    long arr[n];
    for (long i = 0; i < n; i++) cin >> arr[i];

    long minimum = arr[0], maksimum = arr[0];
    for (long i = 0; i < n; i++) {
        if (arr[i] < minimum)
            minimum = arr[i];
        if (arr[i] > maksimum)
            maksimum = arr[i];
    }

    long koraci = 0;
    if (abs(x - minimum) < abs(maksimum - x)) koraci += abs(x - minimum) + abs(maksimum - minimum);
    else if (abs(x - minimum) > abs(maksimum - minimum)) koraci += abs(x - maksimum) + abs(maksimum - minimum);
    else if (x < minimum) koraci += (maksimum - x);
    else if (x > maksimum) koraci += (x - minimum);

    cout << koraci;

    return 0;
}