#include <bits/stdc++.h>
using namespace std;

int main() {
    int n,x,mini,maxi,p;
    scanf("%d %d",&n,&x);
    mini=x;
    maxi=x;
    for (int i=0; i<n; i++) {
        scanf("%d",&p);
        if (p>maxi) maxi=p;
        else if (p<mini) mini=p;
        else continue;
    }
    if (mini==x) {
        cout<<maxi-x;
    }
    else if (maxi==x) {
        cout<<x-mini;
    }
    else if (x-mini<=maxi-x) {
        cout<<(x-mini)*2+(maxi-x);
    }
    else {
        cout<<(maxi-x)*2+(x-mini);
    }
    return 0;
}