using System;

namespace petljazad1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            int[] x = new int[Convert.ToInt32(input1.Substring(0,input1.IndexOf(" ")))];
            int p = Convert.ToInt32(input1.Substring(input1.IndexOf(" ") + 1));
            string input2 = Console.ReadLine();
            int minv = int.MaxValue;
            int rofl = 0;
            while (input2 != "")
            {
                if (input2.IndexOf(" ") != -1)
                {
                    x[rofl] = Convert.ToInt32(input2.Substring(0, input2.IndexOf(" ")));
                    if (x[rofl] < minv)
                        minv = x[rofl];
                    input2 = input2.Substring(input2.IndexOf(" ") + 1);
                }
                else
                {
                    x[rofl] = Convert.ToInt32(input2);
                    if (x[rofl] < minv)
                        minv = x[rofl];
                    input2 = "";
                }
                rofl++;
            }
            int f = x.Length;
            bool[] tr = new bool[x.Length];
            for (int i = 0; i < x.Length; i++)
            {
                tr[i] = false;
            }
            int total = 0;
            int pocetak = p;
            bool lmao = true;
            while (f != 0)
            {
                
                int min = int.MaxValue;
                int ind = 0;

                if (lmao)
                {
                    for (int i = 0; i < x.Length; i++)
                    {
                        if (p == minv)
                        {
                            lmao = false;
                            break;
                        }
                        if (min > Math.Abs(p - x[i]) && x[i] < p && !tr[i])
                        {
                            min = Math.Abs(p - x[i]);
                            ind = i;
                        }
                    }
                }
                if(!lmao)
                {
                    for (int i = 0; i < x.Length; i++)
                    {
                        if (min > Math.Abs(p - x[i]) && x[i] > p && !tr[i])
                        {
                            min = Math.Abs(p - x[i]);
                            ind = i;
                        }
                    }
                }
                tr[ind] = true;
                p = x[ind];

                total += min;
                f--;
            }
            Console.WriteLine(total);
        }
    }
}