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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var linija = Console.ReadLine().Split();
            int n = int.Parse(linija[0]);
            int m = int.Parse(linija[1]);
            int[] a = new int[n];
            var linija2 = Console.ReadLine().Split();
            int k = 0, s;
            int i = 0;
            for ( ; i < n; i++)
            {
                a[i] = int.Parse(linija2[i]);
            }
            Array.Sort(a);
            int l = a.Length - 1;
            if (m < a[0])
                s = a[l] - m;
            else if (m > a[l])
                s = m - a[0];
            else
                s = m - a[0] + a[l] - a[0];
            Console.WriteLine(s);
            Console.ReadLine();
        }
    }
}