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 = MathF.Abs(max - x);
			else if (max <= x)
				d = MathF.Abs(x - min);
			else
				d = MathF.Min(MathF.Abs(max - x), MathF.Abs(x - min)) + MathF.Abs(max - min);
			
			Console.WriteLine(Convert.ToInt32(d));
		}
	}
}