#include<bits/stdc++.h>

using namespace std;

long long int n,x,a[1000100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

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

    long long int maximum = -1000000000;
    for(long long int i = 0;i<n;i++) maximum = max(maximum,a[i]);

    long long int minimum = 1000000000;
    for(long long int i = 0;i<n;i++) minimum = min(minimum,a[i]);

    long long int konacno;
    if(x <= minimum) konacno = maximum - x;
    else if(x >= maximum) konacno = x - minimum;
    else konacno  = min(x-minimum,maximum-x)+(maximum-minimum);

    cout<<konacno;

    return 0;
}