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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            long put = 0;
            long min = 100000;
            long max = -100000;
            long i = 0;
            long n = int.Parse(Console.ReadLine());
            long x = int.Parse(Console.ReadLine());
            long[] niz = new long[n];
            for (i = 0; i < n; i++)
            {
                niz[i] = int.Parse(Console.ReadLine());
            }
            for (i = 0; i < n; i++)
            {
                if (niz[i] > max)
                {
                    max = niz[i];
                }
                if (niz[i] < min)
                {
                    min = niz[i];
                }
            }
            if (max < x && min < x)
            {
                put = x - min; 
            }
            else if (max > x && min > x)
            {
                put = max - x;
            }
            else if (min < x && max > x)
            {
                if (x - min < max - x)
                {
                    put = (x - min) * 2 + (max - x);
                }
                else
                {
                    put = (max - x) * 2 + (x - min);
                }
            }
            Console.WriteLine(put);
            Console.ReadLine();
        }
    }
}