#include <bits/stdc++.h>
using namespace std;
int n, x, l, p, r, sum;
int main() {
  scanf("%d %d", &n, &x);
  int p = 1, next;
  while (n--) {
    scanf("%d %d", &next, &r);
    l = p + ((next - p) / x) * x;
    sum += r - l + 1;
    p = r + 1;
  }
  printf("%d", sum);
  return 0;
}
