using System;
using System.Linq;

namespace petlja
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] unos = Console.ReadLine().Split(); 
			string[] ulaz = Console.ReadLine().Split();
			int n = int.Parse(unos[0]);
			int x = int.Parse(unos[1]);

			int[] coord = new int[n];
			
			for (int i = 0; i < n; i++)
			{
				coord[i] = int.Parse(ulaz[i]);
			}

			int max = coord.Max();
			int min = coord.Min();

			float d = 0;

			if (min >= x)
				d = Math.Abs(max - x);
			else if (max <= x)
				d = Math.Abs(x - min);
			else
				d = Math.Min(Math.Abs(max - x), Math.Abs(x - min)) + Math.Abs(max - min);
			
			Console.WriteLine(Convert.ToInt32(d));
		}
	}
}