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