#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  long long ans = 0;
  int last = 0;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    ans += (r - l + 1);
    ans += (l - 1 - last) % x;
    last = r;
  }
  cout << ans << endl;
  return 0;
}
