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

namespace kvalifikacije
{
    class A
    {
        const long MIN_COORD = 1;
        const long MAX_COORD = 100000000;

        static void Main(string[] args)
        {
            string[] input;

            input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            long x = int.Parse(input[1]);

            input = Console.ReadLine().Split(' ');
            long d = 0;
            long p1 = MAX_COORD;
            long pn = MIN_COORD;
            for (int i = 0; i < n; i++)
            {
                long y = long.Parse(input[i]);
                p1 = Math.Min(p1, y);
                pn = Math.Max(pn, y);
            }
            if (x < p1 && x < pn)
                d = pn - x;
            else if (p1 < x && pn < x)
                d = x - p1;
            else if (x - p1 < pn - x)
                d = 2 * (x - p1) + pn - x;
            else
                d = x - p1 + 2 * (pn - x);
            Console.WriteLine(d);
        }
    }
}