#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b;
  while (scanf("%d%d", &n, &m) != EOF) {
    int sum = 0, t = 1, i;
    for (i = 0; i < n; i++) {
      scanf("%d%d", &a, &b);
      while (1) {
        if ((t + m) > a) {
          break;
        }
        if ((t + m) == a) {
          t = t + m;
          break;
        }
        t = t + m;
      }
      sum += (b - t + 1);
      t = b + 1;
    }
    printf("%d\n", sum);
  }
  return 0;
}
