#include<iostream>
using namespace std;
int main(){
	int n, x, a, br, s, l, d;
    cin >> n >> x;
	l = 0;
	d = 0;
    s = 0;
	long long int y = -100000001;
	long long int z = 100000001;
	br = 0;
    while (br < n) {
        cin >> a;
		if (a > y) {
			y = a;
		}
        if (a < z) {
			z = a;
        }
        br++;
    }
	if (x > z and x > y) {
		s = x - z;
	}
	else {
		if (x < z and x > y) {
			s = x - z + y - z;
		}
		else {
			if (x < z) {
				s = y - x;
			}
		}
	}
    cout<<s;
    return 0;
}