#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  int n, x, r = 0, t = 1, lo, hi;
  cin >> n >> x;
  for (int i = 0; i < n; ++i) {
    cin >> lo >> hi;
    r += (lo - t) % x + hi - lo + 1;
    t = hi + 1;
  }
  cout << r << endl;
  return EXIT_SUCCESS;
}
