#include <bits/stdc++.h>
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  int start = 1, ans = 0;
  int u, v;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &u, &v);
    int flag = (u - start) / x;
    ans += v - (start + x * flag) + 1;
    start = v + 1;
  }
  printf("%d\n", ans);
  return 0;
}
