#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
    long long  int x,n,i,sum;
    cin>>n>>x;
    long long  int a[n];
    for (i = 0; i<n; i++)
    {
        cin>>a[i];
        
    }
    
    sort (a, a+n);
    sum = abs(int(a[0]-x));
    if (abs(int(x-a[0]))<abs(int(x-a[n-1])))
    {
    
        sum = abs(int(a[0]-x));
    for (i = 0 ; i < n-1 ; i ++)
        {
            
            sum = sum + abs(int(a[i+1]-a[i]));
        }
    }
    else
        {
            
            sum = abs(int(a[n-1]-x));
            for (i = n-1 ; i > 0 ; i --)
                  {
                      
                      sum = sum + abs(int(a[i]-a[i-1]));
                  }
            
            
        }
    
    cout<<sum;
    
    
    return 0;
    
}