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

int main()
{
     int n,p;
     scanf("%d%d",&n,&p);
     long a[n];
     for(int i=0;i<n;++i){
          scanf("%ld",a+i);
     }
     sort(a,a+n);

     if(p>*a && p>*(a+n-1)){
          printf("%ld",abs(p-*a));
     }
     else if( p<*a && p<*(a+n-1)){
          printf("%ld",abs(*(a+n-1)-p));
     }
     else {
               if(abs(*(a+n-1)-p)>abs(*a-p))
          printf("%ld",abs(*(a+n-1)-p)+abs(*a-p)*2);
               else printf("%ld",abs(*(a+n-1)-p)*2+abs(*a-p));
     }
    return 0;
}