#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x;
  cin >> n >> x;
  long long a = x;
  long long b = x;
  long long cost = 0;
  for (long long i = 0; i < n; i++) {
    long long c, d;
    cin >> c >> d;
    if (c >= b) {
      cost += (c - b);
      a = b;
      b = c;
      continue;
    }
    if (d <= a) {
      cost += (a - d);
      b = a;
      a = d;
      continue;
    }
    a = max(a, c);
    b = min(b, d);
  }
  cout << cost << endl;
}
