#include <bits/stdc++.h>
using namespace std;
int ans = 0;
int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  for (int i = 0, p = 1, x, y; i < n; ++i) {
    cin >> x >> y;
    ans += (x - p) % k;
    ans += y - x + 1;
    p = y + 1;
  }
  cout << ans;
  return 0;
}
