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