#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  t = 1;
  while (t--) {
    long long n, i, j, w, h, count = 0, sum = 0, total, k, T = 1, breaks = 0, m,
                             x, l, r;
    string s;
    cin >> n >> x;
    for (i = 0; i < n; i++) {
      cin >> l >> r;
      sum = sum + (r - l + 1) + (l - T) % x;
      T = r + 1;
    }
    cout << sum << endl;
  }
}
