#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n, x, l, r, now = 1, ans;
int main() {
  cin >> n >> x;
  while (n--) {
    cin >> l >> r;
    ans += (l - now) % x;
    ans += r - l + 1;
    now = r + 1;
  }
  cout << ans;
  return 0;
}
