#include <bits/stdc++.h>
using namespace std;
int main() {
  int scenes, jump, pos = 1, c = 0, j = 0;
  cin >> scenes >> jump;
  int starts[scenes], ends[scenes];
  for (int i = 0; i < scenes; i++) cin >> starts[i] >> ends[i];
  while (true) {
    if (pos + jump <= starts[j])
      pos += jump;
    else {
      c += (ends[j] + 1 - pos);
      pos = ends[j] + 1;
      j++;
    }
    if (pos == ends[scenes - 1] + 1) break;
  }
  cout << c;
  return 0;
}
