#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(int 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);
    	return 0;
	}
	if(max<=x){
		cout<<x-min;
		return 0;
	}
	if(min>=x){
		cout<<max-x;
		return 0;
	} 
    return 0;
}