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

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nx = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(nx[0]);
            int x = Convert.ToInt32(nx[1]);
            string[] xx=Console.ReadLine().Split(' ');
            int[] a=new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = Convert.ToInt32(xx[i]);
            }
            int j=0;
            int br= 0,br1=0;
            while ( a[j]<x && j<n)
            {
                j++;
            }
            if(a[0]<x)
            br = x - a[0];
            if (j < n)
                br1 = a[n - 1] - x;
            if (br < br1)
                Console.WriteLine(2 * br + br1);
            else
                Console.WriteLine(2 * br1 + br);
            Console.ReadLine();
        }
    }
}