#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  int r[10005], l[10005];
  long long ans = 0;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
  }
  int j = 0, startTime = l[0], endTime = r[0],
      timeBeforNextBig = l[0] - startTime;
  int skip = 1;
  while (j < n) {
    skip += ((startTime - skip) / x) * x;
    ans += (endTime - skip) + 1;
    skip = endTime + 1;
    j++;
    endTime = r[j];
    startTime = l[j];
  }
  cout << ans << endl;
  return 0;
}
