#include <bits/stdc++.h>
int main() {
  int n, i, x, h = 0;
  int t[2][50];
  scanf("%d%d", &n, &x);
  for (i = 0; i < n; i++) {
    scanf("%d%d", &t[0][i], &t[1][i]);
    h = h - t[0][i] + t[1][i] + 1;
  }
  h = h + (t[0][0] - 1) % x;
  for (i = 1; i < n; i++) {
    h += (t[0][i] - t[1][i - 1] - 1) % x;
  }
  printf("%d", h);
  return 0;
}
