#include <iostream>

using namespace std;

int main(void)
{
    unsigned int n;
    cin >> n;

    long int x, a[n];
    cin >> x;

    for(int i=0; i<n; ++i)
        cin >> a[i];

    if(x<a[0])
        cout << a[n-1]-x;
    else if(x>a[n-1])
        cout << x-a[0];
    else if(a[n-1]-x>x-a[0])
        cout << (x-a[0])+(a[n-1]-a[0]);
    else
        cout << (a[n-1]-x)+(a[n-1]-a[0]);
    return 0;
}