#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
     int n,p;
     scanf("%d%d",&n,&p);
     long a1,a2,h;
     scanf("%ld",&a1);
     a2=a1;
     for(int i=0;i<n-1;++i){
          scanf("%ld",&h);
          if(h<a1){
               a1=h;
          }
          if(h>a2){
               a2=h;
          }
     }
     if(p>a1 && p>a2){
          printf("%ld",abs(p-a1));
     }
     else if( p<a1 && p<a2){
          printf("%ld",abs(a2-p));
     }
     else {
               if(abs(a2-p)>abs(a1-p))
          printf("%ld",abs(a2-p)+abs(a1-p)*2);
               else printf("%ld",abs(a2-p)*2+abs(a1-p));
     }
    return 0;
}