#include <iostream>
#include <cmath>

using namespace std;

int main(){

long long n,x,max,min,rez,blizi;

cin >> n >> x;

long long niz[n];

for(int i = 0;i < n;i++)
{
	cin >> niz[i];
}

max = niz[0];
min = niz[0];

for(int i = 0;i < n;i++)
{
	if(niz[i] > max) max = niz[i];
	else if (niz[i] < min) min = niz[i];
}

if(abs(max-x) < abs(min - x)) blizi = abs(max-x);
else  blizi = abs(min - x);

if(min >= x) 
rez = max - x;

else if(max <= x)
rez = x - min;

else if(min < x && blizi == abs(min - x))
rez = 2*blizi + abs(max - x);

else 
rez = 2*blizi + x - min;

cout << rez << endl;

	return 0;
}