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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] a = Console.ReadLine().Split();
            int n = int.Parse(a[0]);
            int x = int.Parse(a[1]);
            string[] dl = Console.ReadLine().Split();
            int min = 2000000000;
            int max = 0;
            int[] komsije = new int[n];
            for (int i = 0; i < dl.Length; i++)
            {
                komsije[i] = int.Parse(dl[i]);
                if (komsije[i] > max)
                    max = komsije[i];
                if(komsije[i]<min)
                    min=komsije[i];
            }
            int sum = 0;
            if (x - min <= max - x && min < x && max > x)
                sum += (2 * (x - min)) + max - x;
            else if (min > x && max > x)
                sum += max - x;
            else if (min < x && max < x)
                sum += x - min;
            else if (x - min >= max - x && min < x && max>x)
                sum += (2 * (max - x)) + x-min;
            Console.WriteLine(sum);
            
        }
    }
}