#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, a, b, end = 0, k = 0;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    k++;
    int start = ((a - k) % x);
    end = end + start + b - a + 1;
    k = end;
  }
  cout << k;
  return 0;
}
