#include <bits/stdc++.h>
using namespace std;
int n, leftx, l, r, rightx;
long long ans = 0;
int main() {
  cin >> n >> leftx;
  rightx = leftx;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    if (rightx >= l && leftx <= r) {
      rightx = min(rightx, r);
      leftx = max(leftx, l);
    } else if (rightx < l) {
      leftx = rightx;
      ans += l - rightx;
      rightx = l;
    } else if (leftx > r) {
      rightx = leftx;
      ans += leftx - r;
      leftx = r;
    }
  }
  cout << ans;
}
