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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {

            int x, n;

            string temp = Console.ReadLine();
            n = Convert.ToInt32(temp.Split(' ')[0]);
            x = Convert.ToInt32(temp.Split(' ')[1]);

            List<int> niz1 = new List<int>();

            temp = Console.ReadLine();
            foreach (string a in temp.Split(' '))//(int i = 0; i < n; i++)
            {
                niz1.Add(Convert.ToInt32(a));
            }

            niz1.Sort();
            int rez;
            int i = 0;


            if (x < niz1[0])
            {
                rez = niz1.Max() - x;
            }
            else if (x > niz1.Max())
            {
                rez = x - niz1[0];
            }
            else
            {
                i = 0;
                while (niz1[i] < x)
                {
                    ++i;
                }

                ; rez = (x - niz1.GetRange(0, i).First<int>()) * 2 + niz1.GetRange(i, niz1.Count - i).Last<int>() - x;
                if (rez > x - niz1.GetRange(0, i).First<int>() + (niz1.GetRange(i, niz1.Count - i).Last<int>() - x) * 2)
                {
                    rez = x - niz1.GetRange(0, i).First<int>() + (niz1.GetRange(i, niz1.Count - i).Last<int>() - x) * 2;
                }
            }

            Console.WriteLine(rez);

            




        }
    }
}