#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, x, ans = 0, a, b, cur = 1;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (cur + x <= a) {
      a = cur + ((a - cur) / x) * x;
      ans += (b - a + 1);
    } else
      ans += (b - cur + 1);
    cur = b + 1;
  }
  cout << ans << endl;
  return 0;
}
