#include <bits/stdc++.h>
using namespace std;
long long n, i, x;
long long le, re;
long long cl, cr;
long long c;
int main() {
  cin >> n >> x;
  cl = cr = x;
  for (i = 0; i < n; i++) {
    cin >> le >> re;
    long long pl, pr;
    pr = min(re, cr), pl = max(le, cl);
    if (pl <= pr) {
      cl = pl, cr = pr;
      continue;
    }
    if (cr < le) {
      c += (long long)le - cr;
      cl = cr, cr = le;
    } else {
      c += (long long)cl - re;
      int v = cl;
      cl = re, cr = v;
    }
  }
  cout << c << endl;
  return 0;
}
