using System;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            long n;
            long k;
            string[] s1 = Console.ReadLine().Split(' ');
            n = Convert.ToInt64(s1[0]);
            k = Convert.ToInt64(s1[1]);
            string[] s2 = Console.ReadLine().Split(' ');
            long min = long.MaxValue;
            long max = long.MinValue;
            for (long i = 0; i < s2.Length; i++)
            {
                long temp = Convert.ToInt64(s2[i]);
                if (temp > max) max = temp;
                if (temp < min) min = temp;
            }
            long num;
            if (Math.Abs(k - min) > Math.Abs(k - max))
            {
                num = Math.Abs(k - max) + Math.Abs(max - min);
            }
            else
            {
                num = Math.Abs(k - min) + Math.Abs(min - max);
            }
            Console.WriteLine(num.ToString());
       }
    }
}