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