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

namespace Upoznavanje
{
    class Program
    {
        static void Main(string[] args)
        {
            var b = Console.ReadLine().Split();
            int n = int.Parse(b[0]);
            int x = int.Parse(b[1]);
            int[] a = new int[n];
            int i, min, max, s;
            var c = Console.ReadLine().Split();
            for (i = 0; i < n; i++)
            {
                a[i] = int.Parse(c[i]);
            }
            min = a[0];
            max = a[0];
            for (i = 0; i < n; i++)
            {
                if (a[i] < min)
                    min = a[i];
                if (a[i] > min)
                    max = a[i];
            }
            if (x < min)
            {
                s = max - x;
            }
            else if (Math.Abs(min - x) > Math.Abs(max - x))
            {
                s = 2 * (Math.Abs(max - x)) + Math.Abs(min - x); 
            }
            else
            {
                s = 2 * (Math.Abs(min - x)) + Math.Abs(max - x);
            }
            Console.WriteLine(s);
        }
    }
}