using System;
class Program {
    static void Main() {
        string s = Console.ReadLine();
        string[] o = s.Split(null);
        int n = int.Parse(o[0]);
        int x = int.Parse(o[1]);
        string j = Console.ReadLine();
        string[] p = j.Split(null);
        int[] k = new int[n];
        int max = x;
        int min = x;
        for(int i = 0; i < n; i++) { 
            k[i] = int.Parse(p[i]);
            max = Math.Max(max, k[i]);
            min = Math.Min(min, k[i]);
        }
        int sum = 0;
        int Raz1 = Math.Abs(max - x);
        int Raz2 = Math.Abs(min - x);
        if(max != x && min != x) {
            if(Raz1 < Raz2) { sum = 2*Raz1 + Raz2; }
            else { sum = 2*Raz2 + Raz1; }
        }
        else if(max == x && min != x) { sum = Raz2; }
        else if(max != x && min == x) { sum = Raz1; }
        Console.WriteLine(sum);
    }
}