#include <bits/stdc++.h>
using namespace std;
inline int get_num() {
  char c;
  int f = 1, num = 0;
  while ((c = getchar()) == ' ' || c == '\n' || c == '\r')
    ;
  if (c == '-')
    f = -1;
  else
    num = c - '0';
  while (isdigit(c = getchar())) num = num * 10 + c - '0';
  return num * f;
}
int main() {
  int n, x;
  cin >> n >> x;
  int ans = 0, last = 1;
  for (int i = 1; i <= n; i++) {
    int l, r;
    cin >> l >> r;
    int k = (l - last) % x;
    ans += (r - l + 1) + k;
    last = r + 1;
  }
  cout << ans;
  return 0;
}
