#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
int n;
char str[maxn][maxn];
char S[maxn];
int main() {
  int n, x;
  cin >> n >> x;
  int m = n;
  int l[n], r[n];
  int t = 0;
  while (m--) {
    cin >> l[n - m] >> r[n - m];
    if (n - m == 1)
      t += (l[n - m] - 1) % x;
    else
      t += (l[n - m] - r[n - m - 1] - 1) % x;
    t += r[n - m] - l[n - m] + 1;
  }
  cout << t << endl;
  return 0;
}
