#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <math.h>
#define ll long long

using namespace std;

int main()
{
    int n, x, prvi, drugi;
    cin >> n >> x;

    vector<int>v(n, 0);

    for (int i = 0; i < v.size(); i++)
        cin >> v[i];

    sort(v.begin(), v.end());
    prvi = abs(v[0] - x) + abs(v[0] - v[v.size() - 1]);
    drugi = abs(v[v.size() - 1] - x) + abs(v[v.size() - 1] - v[0]);

    cout << min(prvi, drugi) << "\n";



    return 0;
}