#include <bits/stdc++.h>
using namespace std;
const int mx = 1e2 + 10;
int m[mx][2];
int n;
int x;
int res;
int main() {
  scanf("%d%d", &n, &x);
  for (int i = 0; i < n; i++) scanf("%d%d", &m[i][0], &m[i][1]);
  int t = 1;
  res = 0;
  for (int i = 0; i < n; i++) {
    int a = m[i][0] - t;
    res += min(a % x, a) + m[i][1] - m[i][0] + 1;
    t = m[i][1] + 1;
  }
  printf("%d", res);
  return 0;
}
