using System;

namespace Competition3._1
{
    class Program
    {
        static void Main(string[] args)
        {
            String input = Console.ReadLine();
            int x;
            int n;
            {
                string[] inp = input.Split(' ');
                n = int.Parse(inp[0]);
                x = int.Parse(inp[1]);
            }
            
            
            
            int[] a = new int[n];
            {
                input = Console.ReadLine();
                string[] inp = input.Split(' ');
                for(int i = 0; i < n; i++)
                {
                    a[i] = int.Parse(inp[i]);
                }
            }
           
            
            int max = x;
            int min = x;
            {
                for(int i = 0; i < n; i++)
                {
                    if(a[i] < min)
                    {
                        min = a[i];
                    }
                    if(a[i] > max)
                    {
                        max = a[i];
                    }
                }
            }

            int outp = 0;
            {
                if (min == x)
                {
                    outp = Math.Abs(max - x);
                }
                else if (max == x)
                {
                    outp = Math.Abs(x - min);
                }
                else if (Math.Abs(x - min) < (Math.Abs(max - x)))
                {
                    outp = Math.Abs(x - min) * 2 + Math.Abs(max - x);
                }
                else if (Math.Abs(x - min) > (Math.Abs(max - x)))
                {
                    outp = Math.Abs(x - min) + Math.Abs(max - x) * 2;
                }
                else if(Math.Abs(x - min) == (Math.Abs(max - x)))
                {
                    outp = Math.Abs(x - min) + Math.Abs(max - x) * 2;
                }
            }

            Console.WriteLine(outp);




        }
    }
}