#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned int number, skip, counter = 0, starts, ends, sub = 0, initiall = 0;
  cin >> number >> skip;
  for (int i = 0; i < number; i++) {
    cin >> starts >> ends;
    while (starts - initiall > skip) {
      initiall += skip;
      if (initiall > starts) {
        initiall -= skip;
        break;
      }
    }
    counter += (starts - initiall) + (ends - starts);
    initiall = ends;
  }
  cout << counter << endl;
}
