#include <iostream>
using namespace std;
int main(){
    unsigned long long n,x,ma,mi;
    cin>>n>>x;
    unsigned long long a[n];
    cin>>a[0];
    mi=a[0];
    ma=a[0];
    for(unsigned long long i=1;i<n;i++){
        cin>>a[i];
        if(mi>a[i])
        mi=a[i];
        if(ma<a[i])
        ma=a[i];}
    if(mi>x) 
    cout<<ma-x;
    else if(ma<x) 
    cout<<x-mi;
    else if(x-mi>ma-x) 
    cout<<ma-mi+ma-x;
    else 
    cout<<x-mi+ma-mi;}