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

namespace ConsoleApplication31
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int x = int.Parse(Console.ReadLine());
            int[] a = new int[10000];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
            }
            int p = a[0]; 
            int q = a[0];
            for (int j = 1; j < n; j++)
            {
                p = Math.Max(a[j], p);
                q = Math.Min(a[j], q);
            }
            int r = 0;
            if (Math.Abs(x - p) > Math.Abs(x - q))
            {
                r = x - q + p - q;
            }
            else
            {
                r = p - x + p - q;
            }
            Console.WriteLine(r);
        }
    }
}