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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s1 = Console.ReadLine().Split(' ');
            long n = Convert.ToInt64(s1[0]);
            long x = Convert.ToInt64(s1[1]);
            string[] s = Console.ReadLine().Split(' ');
            long min = x;
            long max = x;
            long p;
            long r=0;
            for(int i = 0; i<n;i++)
            {
                p = Convert.ToInt64(s[i]);
                if (p > max)
                    max = p;
                if (p < min)
                    min = p;
            }
            long maxi=Math.Abs(max - x);
            long mini = Math.Abs(x - min);
            if (max == x)
                r = mini;
            else if (min == x)
                r = maxi;
            else if (maxi > mini)
                r = mini * 2 + maxi;
            else r = maxi * 2 + mini;
            Console.WriteLine(r);
        }
    }
}