#include <bits/stdc++.h>
using namespace std;
long long i, j, r[100], l[100], n, x, cnt = 1, ans;
int main() {
  cin >> n >> x;
  for (i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
    ans += (l[i] - cnt) % x;
    ans += (r[i] - l[i] + 1);
    cnt = r[i] + 1;
  }
  cout << ans;
  return 0;
}
