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)
        {
            string[] s1 = Console.ReadLine().Split();
            int n = int.Parse(s1[0]);
            int x = int.Parse(s1[1]);
            int[] a = new int[n];
            string[] s2 = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(s2[i]);
            }
            Array.Sort(a);
            if (a[0] >= x) Console.WriteLine(a[n - 1] - x);
            else if (a[n - 1] <= x) Console.WriteLine(x - a[0]);
            else if (a[n - 1] - x < x - a[0]) Console.WriteLine(a[n - 1] - a[0] + a[n - 1] - x);
            else Console.WriteLine(a[n - 1] - a[0] + x - a[0]);
        }
    }
}