#include <bits/stdc++.h>
using namespace std;
int main() {
  int num, plus;
  int ans = 0, save = 0;
  scanf("%d %d", &num, &plus);
  int l, r;
  for (int i = 1; i <= num; i++) {
    scanf("%d %d", &l, &r);
    ans += (l - save - 1) % plus + (r - l + 1);
    save = r;
  }
  printf("%d\n", ans);
}
