#include <bits/stdc++.h> 
using namespace std;
#define ll long long
int main(){
    ll n,x,a,min=100000000,max=0;
    cin>>n>>x;
    for(ll i=0;i<n;++i){
        cin>>a;
        if(a<min){
        	min=a;
		}
		if(a>max){
			max=a;
		}
    }
    if(min<x and max>x){
    	cout<<x-min+(max-min);
	}
	else if(max<=x){
		cout<<x-min;
	}
	else if(min>=x){
		cout<<max-x;
	} 
    return 0;
}