#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  int n, x;
  cin >> n >> x;
  int ans = 0, last = 0;
  while (n--) {
    int l, r;
    cin >> l >> r;
    ans += (l - last - 1) % x;
    ans += r - l + 1;
    last = r;
  }
  cout << ans << endl;
  return 0;
}
