#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, l, r, sum = 0, curr = 1;
  cin >> n >> x;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    curr += ((l - curr) / x) * x;
    sum += l - curr + r - l + 1;
    curr = r + 1;
  }
  cout << sum;
}
