#include <bits/stdc++.h>
using namespace std;
int l[5010][2];
int main() {
  int n, x;
  long long result = 0;
  while (cin >> n >> x) {
    memset(l, 0, sizeof(l));
    result = 0;
    for (int i = 0; i < n; i++) {
      cin >> l[i][0] >> l[i][1];
    }
    int xl = x, xr = x;
    for (int i = 0; i < n; i++) {
      if (l[i][0] <= xl && l[i][1] >= xr) continue;
      if (l[i][1] < xl) {
        result += (xl - l[i][1]);
        xr = xl;
        xl = l[i][1];
      } else if (l[i][0] > xr) {
        result += (l[i][0] - xr);
        xl = xr;
        xr = l[i][0];
      } else {
        if (l[i][0] > xl) {
          xl = l[i][0];
        }
        if (l[i][1] < xr) {
          xr = l[i][1];
        }
      }
    }
    cout << result << endl;
  }
  return 0;
}
