#include <bits/stdc++.h>
using namespace std;
const long long mod1 = 1000000007;
const long long mod9 = 998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    ;
    long long k;
    cin >> k;
    ;
    long long ans = 0;
    long long prev = 1;
    for (long long i = 0; 0 < n ? i < n : i > n; 0 < n ? i++ : i--) {
      long long x, y;
      cin >> x >> y;
      ;
      while (prev + k <= x) prev += k;
      ans += y - prev + 1;
      prev = y + 1;
    }
    cout << (ans) << "\n";
    ;
  }
  return 0;
}
