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