using System;

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

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

            if(min > x)
                Console.WriteLine(max - x);
            else if(max < x)
                Console.WriteLine(x - min);
            else
                Console.WriteLine((x - min < max - x ? x - min : max - x) + (max - min));
        }
    }
}