#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, x;
    cin >> n >> x;

    int in, mn = INT_MAX, mx = INT_MIN;
    for(int i = 0; i < n; i++)
    {
        cin >> in;
        mn = min(mn, in);
        mx = max(mx, in);
    }

    if(x <= mn)
    {
        cout << abs(x-mx);
    }
    else if(x >= mx)
    {
        cout << abs(x-mn);
    }
    else
    {
        cout << min(abs(x-mn), abs(x-mx))*2 + max(abs(x-mn), abs(x-mx));
    }
}