#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, b;
  long long init = 1;
  long long minutes = 0;
  vector<pair<long, long> > in;
  scanf("%lli %lli ", &n, &b);
  for (int i = int(0); i < int(n); i++) {
    long a, b;
    scanf("%li %li", &a, &b);
    in.push_back(make_pair(a, b));
  }
  for (int i = int(0); i < int(n); i++) {
    while (abs(init - in[i].first) >= b) {
      init += b;
    }
    minutes += in[i].first - init;
    minutes += in[i].second - in[i].first + 1;
    init = in[i].second + 1;
  }
  cout << minutes << endl;
  return 0;
}
