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

int main()
{
    int n, x;
    cin >> n >> x;
    int l = x, r = x;
    for(int i = 0; i < n; i++)
    {
        int t;
        cin >> t;

        if(t < x)
        {
            l = min(t, l);
        }
        else if(t > x)
        {
            r = max(t, r);
        }
    }

    cout << min(2 * (x - l) + (r - x), 2 * (r - x) + (x - l)) << "\n";
    return 0;
}