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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string e = Console.ReadLine();
            string[] st = e.Split();
            int n = Convert.ToInt32(st[0]); int x = Convert.ToInt32(st[1]);
            int[] niz = new int[n+1];
            niz[0] = x;
            e = Console.ReadLine();
            st = e.Split();
            for (int i = 1; i <= n; i++)
            {
                niz[i] = Convert.ToInt32(st[i-1]);
            }
            Array.Sort(niz);
            int s = 0;
            if (niz[0] != x)
            {
                s += x - niz[0];
            }
            if (niz[n] != x)
            {
                s += niz[n] - niz[0];
            }
            Console.WriteLine(s);
        }
    }
}