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

namespace ConsoleApplication1
{
    class Program
    {
            static int partition(int []arr, int l, int h) 
        { 
            int pivot = arr[h];  
            int i = (l - 1);  
            for (int j = l; j < h; j++) 
            {
                if (arr[j] < pivot)
                {
                    i++;
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            } 
            int temp1 = arr[i+1]; 
            arr[i+1] = arr[h]; 
            arr[h] = temp1; 
  
            return i+1; 
        }

            static void quickSort(int[] arr, int l, int h)
            {
                if (l < h)
                {
                    int pp = partition(arr, l, h);
                    quickSort(arr, l, pp - 1);
                    quickSort(arr, pp + 1, h);
                }
            }
            
        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 [] niz2 = new int[n];
            for (int i = 0; i < n; i++)
            {
                niz2[i] = int.Parse(niz[i]);
            }
            quickSort(niz2, 0, n - 1);
            int dist=0;
            int distl=Math.Abs(x-niz2[0]);
            int distd=Math.Abs(niz2[n-1]-x);
            if (niz2[0] < x)
            {
                if (niz2[n - 1] <= x)
                {
                    dist = distl;
                }
                else
                {
                    if (distl > distd)
                    {
                        dist = distd + distd + distl;
                    }
                    else
                    {
                        dist = distl + distl + distd;
                    }
                }
            }
            else
            {
                dist = distd;
            }
            Console.WriteLine(dist);
        }
    }
}