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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            int min = 1000000000;
            int max = -1000000000;
            var ulaz = Console.ReadLine().Split();
            int n = int.Parse(ulaz[0]);
            int x = int.Parse(ulaz[1]);
            var ulaz1 = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                int k = int.Parse(ulaz1[i]);
                if (max < k)
                {
                    max = k;
                }
                if (min > k)
                {
                    min = k;
                }
            }
            int s = 0;
            if (Math.Abs(min-x)<Math.Abs(max-x))
            {
                s += Math.Abs(min - x);
                s += Math.Abs(max - min);
            }
            else
            {
                s += Math.Abs(max - x);
                s += Math.Abs(min - max);
            }
            Console.WriteLine(s);
        }
    }
}