#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, skip, counter = 0, position = 1;
  cin >> n >> skip;
  int minutes[2 * n];
  for (int i = 0; i < 2 * n; i++) cin >> minutes[i];
  for (int i = 0; i < 2 * n; i += 2)
    for (int j = position;; j += skip)
      if (minutes[i] == j) {
        counter += minutes[i + 1] - minutes[i] + 1;
        position = minutes[i + 1] + 1;
        break;
      } else if (minutes[i] < j) {
        counter += minutes[i + 1] - (j - skip) + 1;
        position = minutes[i + 1] + 1;
        break;
      }
  cout << counter;
  return 0;
}
