#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, i, l[100005], r[100005];
  cin >> n >> x;
  for (i = 0; i < n; i++) cin >> l[i] >> r[i];
  int time = 1, ans = 0, y;
  for (i = 0; i < n; i++) {
    y = (l[i] - time) % x;
    ans += y + (r[i] - l[i] + 1);
    time = r[i] + 1;
  }
  cout << ans;
  return 0;
}
