#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
    // Data

    ll n, x;
    cin >> n >> x;
    vector<int> left, right;

    // Input

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        if (a < x)
            left.push_back(a);
        else
            right.push_back(a);
    }

    // Algorithm

    ull result = 0;
    ll l_max = 0, r_max = 0;
    ull going_back = 0;

    if (left.size() > 0)                        l_max = abs(x - abs(*min_element(left.begin(), left.end())));
    if (right.size() > 0)                       r_max = abs(x - abs(*max_element(right.begin(), right.end())));
    if (left.size() > 0 && right.size() > 0)    going_back = min(l_max, r_max);

    result = l_max + r_max + going_back;

    // Output

    cout << result;
    return 0;
}