#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];	
	} 
	sort(a,a+n+1);
	 if(abs(x-a[0])>abs(x-a[n]))
	cout<<abs((a[n]-x))*2+abs(x-a[0]);
	else
	  cout<<abs((a[n]-x))+abs((x-a[0]))*2;		
}