#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int x,n;
    int s1=100000000;
    int s2=-100000000;
    cin>>n;
    cin>>x;
    int komsije[n];
    for(int i=0;i<n;i++)
    {
        cin>>komsije[i];
        if(komsije[i]<s1)
        {
            s1=komsije[i];
        }
        if(komsije[i]>s2)
        {
            s2=komsije[i];
        }
    }

    if(s1>x && s2>x)
    {
       cout<<abs(s2-x);
    }
    if(s1<x && s2>x)
    {
        if((abs(x-s1))>=abs(x-s2))
        {
            cout<<abs(x-s1)+abs(x-s2)+abs(x-s2);
        }
        else
        {
            cout<<abs(x-s2)+abs(x-s1)+abs(x-s1);
        }

    }
    if(s1<x && s2<x)
    {
        cout<<abs(x-s1);
    }
}