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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 p = 0;
            string nx = Console.ReadLine();
            Int64 n = Convert.ToInt64(nx.Split(' ')[0]);
            Int64 x = Convert.ToInt64(nx.Split(' ')[1]);
            Int64[] a = new Int64[n];
            string ai = Console.ReadLine();
            for (int i = 0; i < n; i++)
            {
                a[i] = Convert.ToInt64(ai.Split(' ')[i]);
            }
            Array.Sort(a);
            Int64 max = a[n - 1];
            Int64 min = a[0];
            if (Math.Abs(x - max) < Math.Abs(x - min))
            {
                p += Math.Abs(x - max);
                p += Math.Abs(max - min);
            }
            else
            {
                p += Math.Abs(x - min);
                p += Math.Abs(max - min);
            }
            Console.WriteLine(p);
            Console.Read();
        }
    }
}