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