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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string str1 = Console.ReadLine();
            string[] niz1 = str1.Split();
            int n = int.Parse(niz1[0]);
            int x = int.Parse(niz1[1]);
            string str2 = Console.ReadLine();
            string[] niz = str2.Split();
            int max = int.Parse(niz[0]);
            int min = int.Parse(niz[0]);
            for (int i = 1; i < n; i++)
            {
                int a=int.Parse(niz[i]);
                if (a < min)
                    min = a;
                else if (a > max)
                    max = a;
            }
            int dist=0;
            int distl=Math.Abs(x-min);
            int distd=Math.Abs(max-x);
            if (min < x)
            {
                if (max <= x)
                {
                    dist = distl;
                }
                else
                {
                    if (distl > distd)
                    {
                        dist = distd + distd + distl;
                    }
                    else
                    {
                        dist = distl + distl + distd;
                    }
                }
            }
            else
            {

                dist = distd;
            }
            Console.WriteLine(dist);
        }
    }
}