#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long n, h;
    cin >> n >> h;

    long long mindist, maxdist;
    mindist = maxdist = h;

    long long l;
    for (long long i = 0; i < n; i++) {
        cin >> l;

        if (l < mindist)
            mindist = l;
        if (l > maxdist)
            maxdist = l;
    }

    // cout << mindist << " " << maxdist << "\n";
    if ((h - mindist) < (maxdist - h))
        cout << ((h - mindist) * 2 + (maxdist - h));
    else
        cout << ((maxdist - h) * 2 + (h - mindist));
}