#include <bits/stdc++.h>
int main() {
  int n;
  int x;
  int sum = 0;
  std::cin >> n;
  std::cin >> x;
  unsigned int t1 = 0, t2 = 0, tcurr = 1;
  for (int i = 0; i < n; i++) {
    std::cin >> t1;
    std::cin >> t2;
    sum += (t1 - tcurr) % x + t2 - t1 + 1;
    tcurr = t2 + 1;
  }
  std::cout << sum;
  return 0;
}
