#include <bits/stdc++.h>
using namespace std;
int D[100005], P[100005];
int main() {
  int S = 1;
  long long T = 0;
  int N, X;
  scanf("%d %d", &N, &X);
  for (int i = 0; i < N; i++) scanf("%d %d", &D[i], &P[i]);
  for (int i = 0; i < N; i++) {
    int F = D[i] - S;
    int K = (F / X) * X;
    T += F - K + P[i] - D[i] + 1;
    S = P[i] + 1;
  }
  cout << T << endl;
}
