#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, x, a, s = 0, b, t = 0;
  cin >> n >> x;
  while (n--) {
    cin >> a >> b;
    s = s + ((a - t - 1) % x) + (b - a + 1);
    t = b;
  }
  cout << s << endl;
}
