using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Petlja1
{
    class Program
    {
        static void Main(string[] args)
        {
            /////////////
            //UNOS
            /////////////
            String[] input = Console.ReadLine().Split(' ');

            int n = int.Parse(input[0]);
            int x = int.Parse(input[1]);

            String[] inputArray = Console.ReadLine().Split(' ');
            int[] array = new int[n];

            for (int i = 0; i < n; ++i)
            {
                array[i] = int.Parse(inputArray[i]);
            }

            /////////////
            //ALGORITAM
            /////////////

            int min = array.Min();
            int max = array.Max();

            int direction = 0;

            if (x < min) 
            { 
                Console.WriteLine(Math.Abs(x - max));
            }
            else if (x > max) 
            { 
                Console.WriteLine(Math.Abs(x - min));
            } 
            else
            {
                if (Math.Abs(x - min) < Math.Abs(x - max))
                {
                    Console.WriteLine(Math.Abs(x - min) * 2 + Math.Abs(x - max));
                } 
                else
                {
                    Console.WriteLine(Math.Abs(x - max) * 2 + Math.Abs(x - min));
                }
            }

            Console.ReadKey();
        }
    }
}