#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, x;
    cin>>n>>x;
    int a[n+1] = {0};
    a[n]=x;
    for(int i=0; i<n; i++) cin>>a[i];
    sort (a, a+(n+1));
    if(x==a[0]) cout<<a[n]-x;
    else if(x==a[n]) cout<<x-a[0];
    else
    {
        int tr=0, tl=0;
        for(int i=0; i<n; i++)
        {
            tl += a[i+1] - a[i];
            if(a[i+1]==x) break;
        }
        for(int i=n; i>0; i--)
        {
            tr += a[i] - a[i-1];
            if(a[i-1]==x) break;
        }
        if(tl>=tr) cout<<2*tr+tl;
        else cout<<2*tl+tr;
    }
    return 0;
}