#include<iostream>
#include <bits/stdc++.h> 

using namespace std;

int absolute(int x)
{
	if(x<0)
		return -x;
	return x;
}


int main()
{
	int a,b;
	cin>>a>>b;
	int ar[a];
	for(int i=0;i<a;i++)
		cin>>ar[i];
	int n = sizeof(ar)/sizeof(ar[0]); 
	sort(ar,ar+n);
	if(ar[0]>=b)
		cout<<absolute(ar[a-1]-b);
	else if(ar[a-1]<=b)
		cout<<absolute(ar[0]-b);
	else
		cout<<absolute(2*(ar[0]-b))+absolute(ar[a-1]-b);
}