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

namespace ConsoleApplication37
{
    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 (long i = 0; i < n; i++)
            {
                niz[i] = Convert.ToInt64(s1[i]);
            }
            long a = niz.Min();
            long b = niz.Max();
            if (x - a <= b - x) z = Math.Abs((x - a)) * 2 + Math.Abs(b - x);
            if (x - a >= b - x) z = Math.Abs((b - x)) * 2 + Math.Abs(x - a);
            if (x >= b) z = Math.Abs(x - a);
            if (x <= a) z = Math.Abs(b - x);
            Console.WriteLine(z.ToString());
        }
    }
}