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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 min = long.MaxValue;
            Int64 max = long.MinValue;
            var ulaz = Console.ReadLine().Split();
            Int64 n = Int64.Parse(ulaz[0]);
            Int64 x = Int64.Parse(ulaz[1]);
            var ulaz1 = Console.ReadLine().Split();
            for (Int64 i = 0; i < n; i++)
            {
                Int64 k = Int64.Parse(ulaz1[i]);
                if (max < k)
                {
                    max = k;
                }
                if (min > k)
                {
                    min = k;
                }
            }
            Int64 s = 0;
            if (Math.Abs(min - x) < Math.Abs(max - x))
            {
                s += Math.Abs(min - x);
                s += Math.Abs(max - min);
            }
            else
            {
                s += Math.Abs(max - x);
                s += Math.Abs(min - max);
            }
            Console.WriteLine(s);
        }
    }
}