#include <bits/stdc++.h>
using namespace std;
int n, L, R, l, r;
long long ans;
int main() {
  scanf("%d%d", &n, &L);
  R = L;
  while (n--) {
    scanf("%d%d", &l, &r);
    if (l <= R && L <= r)
      L = max(L, l), R = min(R, r);
    else if (R < l)
      ans += l - R, L = R, R = l;
    else if (L > r)
      ans += L - r, R = L, L = r;
  }
  printf("%lld\n", ans);
  return 0;
}
