#include <bits/stdc++.h>
int main() {
  long long int n, x, a, b, c, ans, i, j, k, l, m;
  scanf("%lld %lld", &n, &x);
  m = 1, ans = 0;
  for (i = 0; i < n; i++) {
    scanf("%lld %lld", &a, &b);
    {
      c = (a - m) % x;
      ans = ans + c + (b - a) + 1;
      m = b + 1;
    }
  }
  printf("%lld\n", ans);
}
