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]);
            }

            Array.Sort(niz);

            int resenje;

            if (Math.Abs(x - niz[0]) < Math.Abs(x - niz[n - 1]))
            {
                resenje = Math.Abs(x - niz[0]) + Math.Abs(niz[0] - niz[n - 1]);
            }

            else
            {
                resenje = Math.Abs(x - niz[n - 1]) + Math.Abs(niz[n - 1] - niz[0]);
            }

            Console.WriteLine(resenje);
        }
    }
}