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