#include <iostream>
#include <algorithm>
using namespace std;
main ()
{
    long long    int m;
      long long int y;
    long long int CALC = 0;
        cin>>m>>y;
long long int a[m];
    for(int i=0;i<m;i++)
      {
           cin>>a[i];
    }
    long      long int Min=min(y,*std::min_element(a,a+m));
    long long int Maks=max(y,*std::max_element(a,a+m));
    if(Min==y ||    Maks==y)
    {
        CALC=Maks-Min;}
       else
    {
          if(y-Min<Maks-y){
            CALC=(Maks-y)+2*(y-Min);
        }
        else     if(y-Min>Maks-y)
        {
            CALC  =(y-Min)+2*(Maks-y);
        }
            else{
        CALC=(Maks-y)+2*(y-Min);
        }
    }
    cout<<CALC;
}