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