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