#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, x, a, b, sum = 0, s = 1;
  cin >> n >> x;
  while (n--) {
    cin >> a >> b;
    sum += (b - a + 1);
    sum += (a - s) % x;
    s = b + 1;
  }
  cout << sum << endl;
  return 0;
}
