#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, x, i, c = 0;
  cin >> n >> x;
  vector<pair<long long int, long long int>> a(n);
  for (i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
  c += (a[0].first - 1) % x + a[0].second - a[0].first + 1;
  for (i = 1; i < n; i++) {
    c += (a[i].first - a[i - 1].second - 1) % x + a[i].second - a[i].first + 1;
  }
  cout << c;
  return 0;
}
