#include <bits/stdc++.h>
using namespace std;
long long ans, n, m, q, w, x;
int main() {
  x = 1;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> q >> w;
    while (x + m <= q) x += m;
    ans += q - x + (w - q + 1);
    x = w + 1;
  }
  cout << ans;
  cin >> n;
}
