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

namespace ConsoleApplication1
{
    class Program
    {
        static void max_min(string[] k, ref int max, ref int min)
        {
            for (int i = 0; i < k.Length;i++ )
            {
                int n = Convert.ToInt32(k[i]);
                if (n > max)
                    max = n;
                if (n < min)
                    min = n;
            }
        }
        static void Main(string[] args)
        {
            string[] p = Console.ReadLine().Split();
            int n = Convert.ToInt32(p[0]);
            int x = Convert.ToInt32(p[1]);
            int max = int.MinValue, min = int.MaxValue;
            string[] k = Console.ReadLine().Split();
            max_min(k, ref max, ref min);
            if (min < x && max > x)
            {
                Console.WriteLine(x + max - 2 * min);
            }
            if (x < min && x < max)
            {
                Console.WriteLine(max - x);
            }
            if (x > min && x > max)
            {
                Console.WriteLine(x - min);
            }
            Console.ReadLine();
        }
    }
}