#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	
	unsigned int n,i,j;
	long int x,pom,rez;
	scanf("%d %d",&n,&x);
	long int a[n];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
	for(i = 0 ; i < n - 1; i++)
		for (j = 0 ; j < n - i - 1; j++)
		{
      		if (a[j] > a[j+1]) 
      			{
        			pom = a[j];
        			a[j]   = a[j+1];
        			a[j+1] = pom;
      			}
    	}
    	
    if(a[0]<x && a[n-1]<x)
    	rez = x-a[0];
    else if(a[0]>x && a[n-1]>x)
    	rez = a[n-1]-x;
    else if(a[0]<x && a[n-1]>x){
    		if(a[n-1]-x>=x-a[0])
    			rez=2*(x-a[0])+(a[n-1]-x);
    		else if(a[n-1]-x<x-a[0])
    			rez=(x-a[0])+2*(a[n-1]-x);
    		
	}
	
    printf("%d",rez);	
	
	return 0;
}