#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int x,n;
    cin >> n >> x;
    int Min = 0,Max = 0;
    for(int i = 0;i < n;i++)
    {
        int tmp;
        cin >> tmp;
        if(x - tmp > Max)
        {
            Max = x- tmp;
        }
        else if(x - tmp < Min)
        {
            Min = x - tmp;
        }
    }
    Min = abs(Min);
    Max = abs(Max);
    cout << min(Min,Max)*2 + max(Min,Max);
}