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