#include <bits/stdc++.h>
using namespace std;
long calMovie(int li, int ri, int s, int x) {
  int skp = 0;
  skp = floor((li - s) / x);
  return ri - (s + (skp * x)) + 1;
}
int main() {
  int n, x;
  cin >> n >> x;
  int li, ri, s = 1;
  long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> li >> ri;
    sum += calMovie(li, ri, s, x);
    s = ri + 1;
  }
  cout << sum;
  return (0);
}
