#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, x, p = 1, temp = 0, count = 0, i;
  scanf("%ld%ld", &n, &x);
  long int A[n], B[n];
  for (i = 0; i < n; i++) scanf("%d %d", &A[i], &B[i]);
  for (i = 0; i < n; i++) {
    temp = (A[i] - p) / x;
    if (temp > 0) p = p + temp * x;
    count = count + B[i] - p + 1;
    p = B[i] + 1;
  }
  printf("%ld", count);
  return 0;
}
