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