#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, x;
    cin >> n >> x;
    int leftMostNeighbour = INT_MAX, rightMostNeighbour = INT_MIN, temp;
    for(int i = 0; i < n ; ++i)
    {
        cin >> temp;
        if(temp < leftMostNeighbour)
            leftMostNeighbour = temp;

        if(temp > rightMostNeighbour)
            rightMostNeighbour = temp;
    }

    int T = abs(leftMostNeighbour - x);
    int S = abs(rightMostNeighbour - x);
    int Steps = min(T, S) + rightMostNeighbour - leftMostNeighbour;
    cout << Steps;

    return 0;
}