using System;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int n = Convert.ToInt32(s.Substring(0, s.IndexOf(" ")));
            int x = Convert.ToInt32(s.Substring(s.IndexOf(" ")+1));
            s= Console.ReadLine();
            int[] a = new int[n+1]; int i = 0;
            while (i<n-1)
            {
                a[i] = Convert.ToInt32(s.Substring(0, s.IndexOf(" ")));
                s = s.Substring(s.IndexOf(" ") + 1);
                i++;
            }
            a[n - 1] = int.Parse(s);
            a[n] = x;
            Array.Sort(array: a);
            int t = 0;
            if (x == a[0])
            {
                t = Math.Abs(a[n] - x);
            }
            else if (x == a[n])
            {
                t =Math.Abs(x - a[0]);
            }
            else if (Math.Abs(x-a[0])>Math.Abs(x-a[n-1]))
            {
                t =Math.Abs(a[n] - x + a[n] - a[0]);
            }
            else if (Math.Abs(x - a[0]) < Math.Abs(x - a[n - 1]))
            {
                t = Math.Abs(x - a[0] + a[n] - a[0]);
            }
            Console.WriteLine(t);
        }
    }
}