#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, l, r, t = 1, ans = 0;
  scanf("%d%d", &n, &x);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &l, &r);
    ans += (l - t) % x + r - l + 1;
    t = r + 1;
  }
  printf("%d\n", ans);
  return 0;
}
