/*
 *  author:    milos
 *  created:   25.01.2020 15:47:48
**/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,x;
	cin>>n>>x;
	long long a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	if(a[n-1]<=x)
	{
		cout<<x-a[0];
		return 0;
	}
	if(a[0]>=x)
	{
		cout<<a[n-1]-x;
		return 0;
	}
	cout<<min(a[n-1]-x,x-a[0])*2+max(a[n-1]-x,x-a[0]);
}