using System;
class Program
{
    static void Main(string[] args)
    {
        string[] c = Console.ReadLine().Split(' ');
        int n = Convert.ToInt32(c[0]);
        int a = Convert.ToInt32(c[1]);
        int[] b = new int[n];
        string[] c1 = Console.ReadLine().Split(' ');
        int max = a, min = a;
        for (int i = 0; i < n; i++)
        {
            b[i] = Convert.ToInt32(c1[i]);
            if (b[i] > max) max = b[i];
            if (b[i] < min) min = b[i];
        }
        if (max - a >= a - min) Console.WriteLine((a - min) * 2 + max - a);
        if (max - a < a - min) Console.WriteLine((max - a) * 2 + a - min);
    }
}