#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, l, r;
  long long int ans = 0;
  cin >> n >> x;
  int x1 = x;
  int x2 = x;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &l, &r);
    if (x2 <= l) {
      ans += abs(x2 - l);
      x1 = x2;
      x2 = l;
    } else if (x1 >= r) {
      ans += abs(x1 - r);
      x2 = x1;
      x1 = r;
    } else if (x2 > l && x2 < r && x1 < l) {
      x1 = l;
    } else if (x1 < r && x1 > l && x2 > r) {
      x2 = r;
    } else if (x1 < l && x2 > r) {
      x1 = l;
      x2 = r;
    }
  }
  cout << ans << endl;
}
