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