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

namespace takmicenje_1
{
    class Program
    {
        static void Main(string[] args)
        {
            var ulazna_linija = Console.ReadLine().Split();
            Int64 n = Int64.Parse(ulazna_linija[0]);
            Int64[] a = new Int64[n];
        
            Int64 x = Int64.Parse(ulazna_linija[1]);
            
            Int64 max= -999999999999999999;
            Int64 min = 999999999999999999;
            Int64 k = 0;
            var ulazna_linij = Console.ReadLine().Split();
            for (Int64 i = 0; i < n; i++)
            {
                Int64 b = Int64.Parse(ulazna_linij[i]);
                if (b < min)
                {
                    min = b;
                }
                else
                {
                    if (b > max)
                    {
                        max = b;
                    }
                }
                
                    

            }
         
                if (Math.Abs(max- x) < Math.Abs(x - min)) 
                {
                    k = Math.Abs(max- x) + Math.Abs(max- min);
                }
                else
                {
                    k = Math.Abs(x - min) + Math.Abs(max - min);
                }
       
            Console.WriteLine(k);
        }
    }
}