#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main()
{
    int n;
    int x;
    int brojac=0;
    cin>>n;
    cin>>x;
    int komsije;
    int minimum=100000000;
    int maximum =-100000000;
    for(int i =0;i<n;i++)
    {
        cin>>komsije;
        if(komsije < minimum)
        {
            minimum=komsije;
        }
        if(komsije > maximum)
        {
            maximum=komsije;
        }

    }
    /*int a = sizeof(komsije)/sizeof(komsije[0]);
    sort(komsije,komsije+a);*/
    if(abs(maximum-x) == abs(minimum - x))
    {
        brojac =0;
    }
    else if(abs(maximum-x) < abs(minimum - x))
    {
        brojac = abs(maximum-x)+abs(maximum - minimum);
    }
    else if(abs(maximum-x) > abs(minimum - x))
    {
        brojac = abs(minimum-x)+abs(minimum - maximum);
    }
    cout<<brojac;
    return 0;
}