#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, X, now = 1, tot = 0;
  cin >> N >> X;
  int L[N], R[N];
  for (int a = 0; a < N; a++) {
    cin >> L[a] >> R[a];
    now += (L[a] - now) / X * X;
    if (now > L[a]) {
      now -= X;
    }
    tot += R[a] - now + 1;
    now = R[a] + 1;
  }
  cout << tot << endl;
}
