#include <iostream>
#include <cmath>
using namespace std;   
long int a[1000000];
int main()
{
   long int max, min, t, n,rez,m;

    cin >> n >> m;
    cin >> a[0];
    max = a[0];
    min = a[0];

    for ( t = 1; t < n; t++)
    {
        cin >>  a[t];
        if (max < a[t])
        {
            max = a[t];
        }
        if (min > a[t])
        {
            min = a[t];
        }
    }
    if (m > max)
    {
        rez = m - min;
    }
    else
    {
        if (m < min)
        {
            rez = max - m;
        }
        else
        {
            if (m - min < max - m)
            {
                rez = 2 * (m - min) + max - m;
            }
            else
            {
                rez = 2 * (max - m) + m - min;
            }
        }
    }
    cout << rez;
}