#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, total = 0;
  cin >> n >> x;
  int start[n], end[n];
  for (int i = 0; i < n; i++) cin >> start[i] >> end[i];
  int prev_time = 0;
  for (int i = 0; i < n; i++) {
    total += (start[i] - prev_time - 1) % x;
    total += (end[i] - start[i] + 1);
    prev_time = end[i];
  }
  cout << total << '\n';
  return 0;
}
