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

namespace _1feladat
{
    class Program
    {
        static void Main()
        {
            string elso_sor = Console.ReadLine();
            string masodik_sor = Console.ReadLine();

            string[] tomb1 = elso_sor.Split(' ');
            string[] tomb2 = masodik_sor.Split(' ');

            int x = Convert.ToInt32(tomb1[1]);
            int[] n = new int[Convert.ToInt32(tomb1[0])];

            for(int i = 0;i!= n.Length; i++)
            {
                n[i] = Convert.ToInt32(tomb2[i]);
            }

            int max = n.Max();
            int min = n.Min();
            int ret = 0;

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