#include <bits/stdc++.h>
using namespace std;

int n,x,niz[1000008],maximum,minimum;

int main(){

  cin>>n>>x;
   for(int i=1;i<=n;i++)
    {
      cin>>niz[i];
    }
   minimum=niz[1];
    for(int i=1;i<=n;i++)
    {
      if(minimum>niz[i]) minimum=niz[i];
    }


   maximum=niz[1];
    for(int i=1;i<=n;i++)
    {
      if(maximum<niz[i]) maximum=niz[i];
    }

if(minimum<x and maximum<x){cout<<x-minimum<<endl;}
 else if(minimum>x and maximum>x ){cout<<maximum-x<<endl;}
 else if(minimum<x and maximum>x and (x-minimum)<=(maximum-x)){cout<<(x-minimum)*2+maximum-x<<endl;}
 else if(minimum<x and maximum>x and (x-minimum)>=(maximum-x)){cout<<x-minimum+(maximum-x)*2<<endl;}

  return 0;
}