using System;

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

            //int[] a = new int[n];
            int a, min = int.MaxValue, max = int.MinValue;
            s = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
            {
                a = int.Parse(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));
        }
    }
}