#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long MOD = 1e9 + 7;
long long inf = 1e9 + 7;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, x;
  cin >> n >> x;
  long long left = x;
  long long right = x;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    if (a > right) {
      ans += a - right;
      left = right;
      right = a;
    } else if (b < left) {
      ans += left - b;
      right = left;
      left = b;
    } else {
      left = max(left, a);
      right = min(right, b);
    }
  }
  cout << ans;
}
