#include <iostream>
#define MAXN 1000001
using namespace std;

int n, x, a[MAXN];

int main()
{
    cin >> n >> x;
    int minA = 1e8 + 1, maxA = -1e8 - 1;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        minA = min(minA, a[i]);
        maxA = max(maxA, a[i]);
    }
    
    int l = max(0, x - minA), r = max(0, maxA - x);
    cout << min(2*l + r, 2*r + l) << '\n';
}