#include <iostream>
#include <bits/stdc++.h>
using namespace std;
//[]
int main()
{
    int x, n;
    cin >> x >> n;
    int a[x];
    for(int i = 0; i < x; i++)
        cin >> a[i];

    sort(a, a+x);

    if(n <= a[0])
        cout << a[x-1]-n;
    else if(n >= a[x-1])
        cout << n-a[0];
    else if(a[x-1]-n <= n-a[0])
        cout << a[x-1]-n+a[x-1]-a[0];
    else cout << n-a[0]+a[x-1]-a[0];

    return 0;
}