#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	long n,x,bm=0,bv=0,r,bs=0,min,max;
	cin>>n>>x;
	long a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]<x) 
		{
		bm++;}
		else
		{
			bv++;
		}
		
	}
	sort(a,a+n);
	
	if((bv==0)&&(bm>0))
	{
	bs=abs(x-a[0]);
		
		cout<<bs;
		exit(0);
	}
	if((bv>0)&&(bm==0))
	{
	bs=abs(x-a[n-1]);
	     cout<<bs;
		exit(0);
		
	}
	if(bm>=bv)
	{
	bs=2*abs(x-a[n-1]);	
	bs+=abs(x-a[0]);
	  cout<<bs;
		exit(0);		
	}
	else
	{
	bs=abs(x-a[n-1]);	
	bs+=2*(abs(x-a[0]));
	  cout<<bs;
   	exit(0);
	}
	
	return 0;
}