#include <bits/stdc++.h>
using namespace std;
int L[100100], R[100100];
int main() {
  int n, x, ti = 1, ans = 0;
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> L[i] >> R[i];
    ans += R[i] - L[i] + 1;
  }
  for (int i = 1; i <= n; i++) {
    ans += (L[i] - ti) % x;
    ti = R[i] + 1;
  }
  cout << ans << endl;
  return 0;
}
