#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, r, l, x, aux, t, ini = 1, sum = 0;
  cin >> n >> x;
  while (n--) {
    cin >> r >> l;
    t = (r - ini) / x;
    sum += l - (ini + t * x) + 1;
    ini = l + 1;
  }
  cout << sum << endl;
  return 0;
}
