#include<stdio.h>
 
int main()
{
	int a[100],i,n,large,small,x,x1,x2,c;
	scanf("%d",&n);
	for(i=0;i<n;++i)
		scanf("%d",&a[i]);
	large=small=a[0];
	for(i=1;i<n;++i)
	{
		if(a[i]>large)
			large=a[i];
		if(a[i]<small)
			small=a[i];
	}
	scanf("%d",&x);
	x1=large-x;
	x2=x-small;
	if(x>large)
	{
	    c=x-small;
	    //printf("%d",c);goto end;
	}
	else if(x<small)
	{
	    c=large-x;
	    //printf("%d",c);goto end;
	}
	else if(x2<x1)
	{
	    c=2*x2+x1;
	    //printf("%d",c);goto end;
	}
	else if(x1<x2)
	{
	    c=2*x1+x2;
	    //printf("%d",c);goto end;
	}
	else if(x1=x2)
	{
	    c=2*x2+x1;
	    //printf("%d",c);goto end;
	}
	end:
	return 0;
}