#include<bits/stdc++.h>

using namespace std;

int n, x, a[1000010], mn=100000010, mx=-100000010;

int main()
{
    scanf("%i%i", &n, &x);
    for (int i = 0; i < n; ++i)
    {
        scanf("%i", &a[i]);
        if (mn > a[i]) mn = a[i];
        if (mx < a[i]) mx = a[i];
    }
    cout << mx-mn + min(abs(x-mn), abs(x-mx));
}