#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  int l, r, t = 0;
  int s = 1;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    t += (((l - s) % x));
    t += (r - l + 1);
    s = r + 1;
  }
  cout << t << endl;
  return 0;
}
