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

int main()
{
    int n,x;
    cin >> n >> x;
    int *niz = new int[1000000];
    for (int i=0;i<n;i++) {
        cin >> niz[i];
    }
    int a = sizeof(niz) / sizeof(niz[0]);
    sort(niz,niz+n);

    int zbir = 0;
    if (abs(niz[0] - x) < abs(niz[n-1] - x)) {
        zbir += abs(niz[0] - x);
        zbir += abs(niz[n-1] - niz[0]);
    } else {
        zbir += abs(niz[n-1] - x);
        zbir += abs(niz[0] - niz[n-1]);
    }


    cout << zbir;
    return 0;
}