#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n, m, mini, maxi, br;
    cin >> n >> m >> br;
    mini = br;
    maxi = br;
    for(int i = 1 ; i < n ; i++){
        cin >> br;
        if(br > maxi) maxi = br;
        else if(br < mini) mini = br;
    }
    if(mini <= m && maxi <= m) cout << m - mini;
    else if(mini >= m && maxi >= m) cout << maxi - m;
    else cout << (m - mini) * 2 + maxi - m;
    return 0;
}