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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            long put = 0;
            long min = 100000;
            long max = -100000;
            long i = 0;
            string s = Console.ReadLine();
            long n = long.Parse(s.Split(' ')[0]);
            long x = long.Parse(s.Split(' ')[1]);
            string g = Console.ReadLine();
            long[] niz = new long[n];
            string[] splitirano = g.Split(' ');
            for (i = 0; i < n; i++)
            {
                niz[i] = long.Parse(splitirano[i]);
            }
            for (i = 0; i < n; i++)
            {
                if (niz[i] > max)
                {
                    max = niz[i];
                }
                if (niz[i] < min)
                {
                    min = niz[i];
                }
            }
            if (max < x && min < x)
            {
                put = x - min; 
            }
            else if (max > x && min > x)
            {
                put = max - x;
            }
            else if (min < x && max > x)
            {
                if (x - min < max - x)
                {
                    put = (x - min) * 2 + (max - x);
                }
                else
                {
                    put = (max - x) * 2 + (x - min);
                }
            }

            Console.WriteLine(put);
            Console.ReadLine();
    
        }
    }
}