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