using System;

class TakZad1
{
    static void Main() {
        string str1 = Console.ReadLine();
            string []niz1 = str1.Split(null);
            int n = int.Parse(niz1[0]); 
            int x = int.Parse(niz1[1]);
        string str2 = Console.ReadLine();
            string []niz2 = str2.Split(null);
            int[]niz3 = new int[n];
        int max = x;
        int min = x;
        for(int i = 0; i<n; i++){
            niz3[i] = int.Parse(niz2[i]);
            max = Math.Max(max, niz3[i]);
            min = Math.Min(min, niz3[i]);
        }
        int d;
        if(x <= min){
            min = x;
            d = Math.Abs(max - min);
        }
        else if(x >= max){
            max = x;
            d = Math.Abs(max - min);
        }
        else {
            if(Math.Abs(max-x) > Math.Abs(x-min)){
                d = Math.Abs((max - min + x-min));
            }
            else{
                d = Math.Abs(max - min + max-x);
            }
        }
        Console.WriteLine(d);
    }
}