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

namespace ConsoleApplication35
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            long n = Convert.ToInt64(s[0]);
            long x = Convert.ToInt64(s[1]);
            long z = 0;
            string[] s1 = Console.ReadLine().Split(' ');
            long[] niz = new long[n];
            for (int i = 0; i < n; i++)
            {
                niz[i] = Convert.ToInt64(s1[i]);
            }
            Array.Sort(niz);
            if (x - niz[0] <= niz[n - 1] - x) z = (x - niz[0]) * 2 + niz[n - 1] - x;
            if (x - niz[0] >= niz[n - 1] - x) z = (niz[n - 1] - x) * 2 + x - niz[0];
            if (x >= niz[n - 1]) z = x - niz[0];
            if (x <= niz[0]) z = niz[n - 1] - x;
            Console.WriteLine(z.ToString());

        }
    }
}