#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, cnt = 0, l, r, last = 1;
  cin >> n >> x;
  for (int i = 0; i < n && cin >> l >> r; i++) {
    cnt += (l - last) % x;
    cnt += r - l + 1;
    last = r + 1;
  }
  cout << cnt;
  return 0;
}
