using System;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            string s = Console.ReadLine();
            
            string[] s1 = s.Split(' ');
            
            int n = int.Parse(s1[0]);
            double x = double.Parse(s1[1]);

            string q = Console.ReadLine();
            string[] q1 = q.Split(' ');
            double[] niz = new double[n];

            

            
            for (int i = 0; i < n ; i++)
            {
                niz[i] = double.Parse(q1[i]);
            }
            double max = niz[0], min = niz[0];
            for (int i = 1; i < n; i++)
            {
                if (max < niz[i])
                    max = niz[i];

                if (min > niz[i])
                    min = niz[i];

            
            }
            double rez;

            if (x < min)
            { rez = max - x; }

            else if (x > max)

            { rez = x - min; }
            
            else 

            {
            if (Math.Abs(min - x) < Math.Abs(max - x))
            {
                
                rez = Math.Abs(min - x) * 2 + Math.Abs(max - x);

            }
            else 
            { 
                rez = Math.Abs(min - x) + Math.Abs(max - x)*2;
            }
            }
            
            
            Console.Write(rez);
            
           

        }
    }
}