#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;
int n,x,a[1000005];
int sol, min1 , min2;

int main(){
    scanf("%d",&n);
    scanf("%d",&x);
    for (int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
    }
    sort(a+1, a+1+n);

    if (a[1] > x)
        cout << a[n]-x << endl;
    else if (a[n] < x)
        cout << x - a[n] << endl;
    else if (x-a[1] < a[n]-x)
        cout << abs(2*(x-a[1]))+ abs(a[n]-x) << endl;
    else
        cout << abs(x-a[1]) + abs(2*(a[n]-x)) << endl;

    return 0;
}