#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 11;
const int inf = 1e9 + 11;
const int mod = 1e9 + 7;
int p[maxn];
int n, x;
void work() {
  memset(p, 0, sizeof(p));
  int ed = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    for (int j = x; j <= y; j++) p[j] = 1;
    if (y > ed) ed = y;
  }
  bool flag = 0;
  int ans = 0, m = 0;
  for (int i = 1; i <= ed; i++) {
    if (p[i] == 0) m++;
    if (p[i] == 1) {
      ans++;
      if (m > 0) {
        ans += (m % x);
        m = 0;
      }
    }
  }
  printf("%d\n", ans);
}
int main() {
  while (~scanf("%d%d", &n, &x)) {
    work();
  }
  return 0;
}
