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

namespace ConsoleApp38
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, x,max=int.MinValue,min=int.MaxValue;
            string[] r2 = Console.ReadLine().Split();
            n = int.Parse(r2[0]);
            x = int.Parse(r2[1]);
            int[] a = new int[n];
            string[] r = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
                a[i] = int.Parse(r[i]);
            for (int i = 0; i < n; i++)
            {
                if (a[i] > max) max = a[i];
                if (a[i] < min) min = a[i];
            }
            if (x <= min)
            {
                int gg = Math.Abs(x - max);
                Console.WriteLine(gg);
            }
            else if (max <= x)
            {
                int dg = Math.Abs(x - min);
                Console.WriteLine(dg);
            }
            else
            {

                int dg = Math.Abs(x - min);
                int gg = Math.Abs(x - max);

                if (dg > gg) Console.WriteLine(gg * 2 + dg);
                else Console.WriteLine(dg * 2 + gg);
            }
            Console.ReadLine();
        }
    }
}