#include <iostream>
#include <bits/stdc++.h>

using namespace std;
vector <int> a;
int main()
{
    int n, x, res,mini, maxi;
    cin >> n >> x;
    int c;
    cin >> c;
    mini=c, maxi=c;
    a.push_back(c);
    for (int i=1;i<n;i++)
    {
        cin >> c;
        a.push_back(c);
        if (c<mini) mini=c;
        if (c>maxi) maxi=c;
    }
    if (x>=mini && x <=maxi){
    if ((x-mini)>(maxi-x)) res=2*(maxi-x)+x-mini;
    else res=2*(x-mini)+maxi-x;}
    else if (x<mini) res=maxi-x;
    else res=x-mini;
    cout << res;

    return 0;
}