#include <iostream>

using namespace std;


void zamena(int* a, int* b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

int partition (int niz[], int low, int high)
{
    int pivot = niz[high]; // pivot
    int i = (low - 1); // Index of smaller element

    for (int j = low; j <= high - 1; j++)
    {
        if (niz[j] < pivot)
        {
            i++;
            zamena(&niz[i], &niz[j]);
        }
    }
    zamena(&niz[i + 1], &niz[high]);
    return (i + 1);
}


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

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

int main() {
    int brKomsija, MilosX;
    cin >> brKomsija >> MilosX;
    int koordinate[brKomsija];
    for(int i = 0; i<brKomsija; ++i) {
        cin >> koordinate[i];
    }
    int distanca;
    brziSort(koordinate,0,brKomsija-1);
    if(abs(koordinate[0]-MilosX) < abs(koordinate[brKomsija-1]-MilosX))
        distanca = abs(koordinate[0]-MilosX) + abs(koordinate[brKomsija-1]-koordinate[0]);

    else distanca = abs(koordinate[brKomsija-1]-MilosX) + abs(koordinate[brKomsija-1]-koordinate[0]);
    cout << distanca;
    return 0;
}