#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  int a = x, b = x;
  long long r = 0;
  for (int i = 0; i < n; i++) {
    int lstart, lend;
    cin >> lstart >> lend;
    if (lend < a) {
      r += (a - lend);
      tie(a, b) = make_pair(lend, a);
    } else if (b < lstart) {
      r += (lstart - b);
      tie(a, b) = make_pair(b, lstart);
    } else {
      tie(a, b) = make_pair(max(a, lstart), min(b, lend));
    }
  }
  cout << r << endl;
}
