#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, x;
  cin >> n >> x;
  long long int l[100], r[100];
  for (long long int j = 0; j < n; j++) {
    cin >> l[j] >> r[j];
  }
  long long int ans = 0;
  ans = (l[0] - 1) % x;
  ans = ans + r[0] - l[0] + 1;
  long long int v = r[0] + 1;
  for (long long int i = 1; i < n; i++) {
    ans = ans + (l[i] - v) % x;
    ans = ans + r[i] - l[i] + 1;
    v = r[i] + 1;
  }
  cout << ans << endl;
}
