#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, e, sum = 0, f = 0;
  scanf("%d%d", &a, &b);
  for (c = 0; c < a; c++) {
    scanf("%d %d", &d, &e);
    sum = sum + e + 1 - d + (d - f - 1) % b;
    f = e;
  }
  printf("%d\n", sum);
  return 0;
}
