#include <stdio.h>
#include <iostream>
#include <cstdlib>

using namespace std ;

int main()
{
    
    std::ios::sync_with_stdio(false) ;
    int n , x , u , lp , dp ;
    int put = 0 ;
    lp = 0 ;
    dp = 0 ;
    
    scanf( "%d %d" , &n , &x ) ;
    int najdes = -2147483648 ;
    int najlev = 2147483647 ;
    
    //cout << n << " " << x ;
    //cout << najlev << " "  << najdes ;
    
    for ( int i = 0 ; i < n ; i++ )
    {
        
        cin >> u ;
        
        if ( u < x )
        {
           
           if ( u < najlev ) { najlev = u ; lp = 1 ;}
            
        }
        
        else
        {
            
            if ( u > najdes ) { najdes = u ; dp = 1 ;}
            
        }
        
    }
    
    if ( lp == 1 && dp == 1 )
    {
        
        if ( najdes - x > abs ( x - najlev ) ) { put = abs ( (najlev - x )*2 ) + (najdes - x) ; }
        else { put = ( najdes - x ) * 2 + abs ( najlev - x ) ; }
        //cout << "OBA" ;
        
    }
    
    else
    {
    
        if ( lp == 1 ) { put = abs ( najlev - x ) ; }
        else { put = najdes - x ; }
    
    }
    
    
    cout << put ;
    
    return 0;
    
}