#include <stdio.h>
#include <math.h>

int main(){
	int n,i,x,u=0;
	scanf("%d%d",&n,&x);
	int ko[n];
	
	for(i=0;i<n;i++)
		scanf("%d",&ko[i]);
	
	int mini1 = ko[0];
	
	for(i=1;i<n;i++)
		if(ko[i]<mini1)	mini1 = ko[i];
	
	int mini = mini1 - x;
	
	int maks1 = ko[0];
	
	for(i=1;i<n;i++)
		if(ko[i]>maks1)	maks1 = ko[i];
	
	int maks = maks1 - x;
	
	if(mini1>x)	u = maks;
	else if(maks1<x) u = abs(mini);
	else if(abs(mini) < maks)   u = 2*abs(mini) + abs(maks);
	else if(abs(mini) > maks)	u = abs(mini) + 2*abs(maks);
	
	printf("%d",u);
	return 0;
}