#include <bits/stdc++.h>
using namespace std;
struct nodo {
  int l, r;
};
nodo a[100010];
int n, x;
int sumn;
int main() {
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].l >> a[i].r;
    sumn = sumn + (a[i].r - a[i].l + 1);
  }
  int st = 0;
  for (int i = 1; i <= n; i++) {
    sumn = sumn + ((a[i].l - st - 1) % x);
    st = a[i].r;
  }
  cout << sumn << endl;
  return 0;
}
