#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1000005;
ll niz[maxn];
ll n, x;
int main()
{
	cin >> n >> x;
	ff(i,0,n-1)cin >> niz[i];
	sort(niz, niz+n);
	if(niz[0] > x)return cout << niz[n-1] - x, 0;
	if(niz[n-1] < x)return cout << x - niz[0], 0;
	if(x - niz[0] < niz[n-1] - x)cout << x - niz[0] + niz[n-1] - niz[0] << endl;
	else cout << niz[n-1] - x + niz[n-1] - niz[0] << endl;
	return 0;
}