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