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

namespace Zadatak_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] unos = new string[2];

            unos = Console.ReadLine().Split(' ');

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

            unos = new string[n];

            unos = Console.ReadLine().Split(' ');

            int[] niz = new int[n];

            for (int i = 0; i < n; i++)
            {
                niz[i] = Convert.ToInt32(unos[i]);
            }

            int min = niz[0];
            int max = niz[0];

            for (int i = 1; i < n; i++)
            {
                if (niz[i] < min)
                {
                    min = niz[i];
                }

                if (niz[i] > max)
                {
                    max = niz[i];
                }
            }

            int resenje;

            if (Math.Abs(x - min) < Math.Abs(x - max))
            {
                resenje = Math.Abs(x - min) + Math.Abs(min - max);
            }

            else
            {
                resenje = Math.Abs(x - max) + Math.Abs(max - min);
            }

            Console.WriteLine(resenje);
        }
    }
}