#include <bits/stdc++.h>
using namespace std;
long long n, x;
int main() {
cin >> n >> x;
int a[n+5];
double y=-100000000;
double j=1000000000;
for(int i=1; i<=n; i++) {
    cin >> a[i];
    if(y<a[i]) y=a[i];
}
for(int i=1; i<=n; i++) {
    cin >> a[i];
    if(j>a[i]) j=a[i];
}
if(j<x) cout << (x-j)+(y-x) << endl;
else cout << y-x << endl;
return 0;
}