#include <stdio.h>
#include <stdlib.h>

#define ll long long


int comp(const void *a,const void *b) {
ll int *x = (ll int *) a;
ll int *y = (ll int *) b;
return *x - *y;
}

int main()
{
	ll int n,x;
	scanf("%lli %lli", &n, &x);
	ll int k[n];
	ll int temp;
	ll int rez;
	for (ll int i = 0; i < n; ++i)
	{
		scanf("%lli", &k[i]);
	}
	qsort(k, n, sizeof(*k), comp);

	if(x>k[n-1])     //IDE LEVO
	{
		rez = abs(k[0]-x);
	}
	else if (x<k[0])   //IDE DESNO
	{
		rez = abs(k[n-1]-x);
	}
	else
	{
		if(abs(k[0]-x) > abs(k[n-1]-x))
		{
			rez = abs(k[n-1]-x)+abs(k[n-1]-k[0]);
		}
		else if(abs(k[0]-x) < abs(k[n-1]-x))
		{
			rez = abs(k[0]-x)+abs(k[0]-k[n-1]);
		}
	}

	printf("%lli\n", rez);

	return 0;
}