#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int najm=100000001,najv=-100000001;
    int n,x,brojacd=0,brojacl=0,t;
    scanf("%d %d",&n,&x);
    int xk[n];
    for (int i=0; i<n; i++)
    {
        scanf("%d",&xk[i]);
        if (xk[i]>najv)
        {
            najv=xk[i];
        }
        if (xk[i]<najm)
        {
            najm=xk[i];
        }

        if (xk[i]>x)
        {
            brojacd++;
        }
        else
        {
            brojacl++;
        }
    }
    if (brojacd==n || brojacl==n)
    {
        t=abs(najv-x);
    }
    else
    {
        t=min((x-najm),(najv-x))*2+max((x-najm),(najv-x));
    }
    printf("%d",t);
}