#include <iostream>
using namespace std;
#include<cmath>
#include<algorithm>

int main(int argc, char** argv)
 {
 	long n,x;
    cin>>n>>x;
    long a[n+1];
	a[0]=x;
	for(long i=1;i<n+1;i++)
	{ 
	   cin>>a[i];	
	} 
	long ind=0;
	sort(a,a+n+1);
	for(long i=0;i<n+1;i++)
	{
	    if(a[i]==x)
		{
	       	ind=i;
	       	break;
		}	
		
	}
	long s=0;
	for(long i=0;i<n+1;i++)
	{
	   if(abs(x-a[0])>abs(x-a[n]))
	
	   	s=abs((a[n]-x))*2+abs(x-a[0]);
	
	else
	
	  s=abs((a[n]-x))+abs((x-a[0]))*2;	
	
		}
    cout<<s;
	
}