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

namespace Prvi_Zadatak
{
    class Program
    {
        static void Main()
        {
            int min = 1000000000, max = -1000000000;
            string[] s = Console.ReadLine().Split(' ');
            int brojUpisa = Convert.ToInt32(s[0]);
            int pozicijaMilosa = Convert.ToInt32(s[1]);
            s = Console.ReadLine().Split(' ');
            for (int i = 0; i < brojUpisa; i++)
            {
                int temp = Convert.ToInt32(s[i]);
                if (temp > max) max = temp;
                if (temp < min) min = temp;
            }
            min -= pozicijaMilosa;
            max -= pozicijaMilosa;
            min = -min;
            if (min < 0) Console.WriteLine(max);
            else if (min > max) Console.WriteLine(2*max+min);
            else Console.WriteLine(max + 2 * min);
        }
    }
}