#include <bits/stdc++.h>

using namespace std;

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

    sort(a, a+n);

    int br = 0;

if(abs(x -a[0]) <= abs(x - a[n-1])){
    if(a[0] >= x)
        br+= a[0] -x;
 else
    br+= x - a[0];

     for(int i = 1;i < n;i++){
            if(a[i] == a[i-1])
            br+= 0;
        br+=a[i] - a[i-1];
    }
    cout << br;
}
   if(abs(x- a[0]) > abs(x - a[n-1])){
    if(a[n-1] >= x)
        br = a[n-1] -x;

 else
    br= x - a[n-1];
     for(int i = 1;i < n;i++){
            if(a[i] == a[i-1])
            br+= 0;
        br+=a[i] - a[i-1];
    }
    cout << br;}
    return 0;
}