#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, a1 = 1, b, conter = 0;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    conter += ((a - a1) % m);
    if (a == 1) {
      conter += b;
    } else {
      conter += (b - a);
      conter += 1;
    }
    a1 = (b + 1);
  }
  cout << conter << endl;
  return 0;
}
