using System;

namespace A_Upoznavanje
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            long x = int.Parse(s[1]);

            s = Console.ReadLine().Split();
            long min = long.MaxValue, max = long.MinValue;
            for (int i = 0; i < n; i++)
            {
                long a = long.Parse(s[i]);
                if (a > max)
                {
                    max = a;
                }

                if (a < min)

                {
                    min = a;
;               }
            }

            if (min > max)
            {
                long t = min;
                min = max;
                max = min;
            }

            Console.WriteLine((x > min ? 2 * Math.Abs(x - min) : 0) + (x < max ? Math.Abs(x - max) : 0));
        }
    }
}