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

namespace ZAadatak_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int n = int.Parse(str[0]);
            int x = int.Parse(str[1]);
            str = Console.ReadLine().Split();
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(str[i]);
            }
            Array.Sort(a);
            int min = a[0];
            int max = a[n - 1];
            if (x <= min)
            {
                Console.WriteLine(max - x);
            }
            else if (x >= max) Console.WriteLine(x - min);
            else
            {
                int kraci = x - min;
                int kraci1 = max - x;
                int blize = Math.Min(kraci, kraci1);
                if (blize == kraci) Console.WriteLine(blize * 2 + kraci1);
                else Console.WriteLine(blize * 2 + kraci);
            }
        }
    }
}