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

namespace ConsoleApplication31
{
    class Program
    {
        static void Main(string[] args)
        {
            var ulaz = Console.ReadLine().Split();
            int n = int.Parse(ulaz[0]);
            int x = int.Parse(ulaz[1]);
            int[] a = new int[10000];
            var ulazz = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(ulazz[i]);
            }
            int p = a[0];
            int q = a[0];
            for (int i = 1; i < n; i++)
            {
                p = Math.Max(a[i], a[i - 1]);
                q = Math.Min(a[i], a[i - 1]);
            }
            int r = 0;
            int d = Math.Abs(p - x);
            int l = Math.Abs(x - q);
            if (x >= l)
            {
                r = d - x;
                Console.WriteLine(r);
                return;
            }
            if (x <= d)
            {
                r = x - l;
                Console.WriteLine(r);
                return;
            }
            if (d>l)
            {
                r = x - q + p - q;
            }
            if (l>d)
            {
                r = p - x + p - q;
            }
            Console.WriteLine(r);
        }
    }
}