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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    int n, x;
    cin>>n>>x;
    int min = 2147483647;
    int max = -2147483648;
    int a[10000000];
    int res = 0;
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
        if(a[i] > max)
            max = a[i];
        if(a[i] < min)
            min = a[i];
    }
    if(min < x)
    {
        res += x-min;
        res += max - min;
    }
    else
        res += max - x;

    cout<<res;
    return 0;
}