#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);

    int n,x; cin>>n>>x;
    vector <int> v;

    int min = x, max = x;
    for (int i = 0; i<n; i++) {
        int temp; cin>>temp; v.push_back(temp);
        if (temp > max) max = temp;
        if (temp < min) min = temp;
    }

    int count;
    if (x-min < max-x)
        count = x+max - 2*min;
    else
        count = 2*max - x-min;

    cout<<count<<endl;

    return 0;
}