#include <bits/stdc++.h>
using namespace std;
int n, x, l, r;
long long res;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x;
  l = r = x;
  for (int i = 0; i < n; i++) {
    int s, e;
    cin >> s >> e;
    if (l < s) l = min(r, s);
    if (r > e) r = max(l, e);
    if (r < s) res += s - r, l = r, r = s;
    if (l > e) res += l - e, r = l, l = e;
  }
  cout << res << '\n';
}
