import java.util.Scanner;

public class Upoznavanje {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int x=scan.nextInt();
		int max=scan.nextInt();
		int min=scan.nextInt();
		
		if(min>max) {
			int p = min;
			min = max;
			max = p;		
		}
		int z;
		for(int i=2;i<n;i++) {
			z=scan.nextInt();
			if (z < min) {
				min=z;
			}	
				
			if (z > max){
				max=z;
			}	
		}
		
		if (x <= min)
			System.out.println(max-x);
		else if (x >= max)
			System.out.println(x-min);
		else {
			int h = x - min;
			int j = max - x;
			if (h < j)
				System.out.println(2*h+j);
			else
				System.out.println(2*j+h);
		}

		}
	}