#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, x;
  cin >> n >> x;
  int mins = 0;
  int prevr = 1;
  for (int i = 0; i < int(n); i++) {
    int l, r;
    cin >> l >> r;
    mins += ((l - prevr) % x + ((r - l) + 1));
    prevr = r + 1;
  }
  cout << mins << endl;
}
