#include <bits/stdc++.h>
using namespace std;
int n, x;
int arr[52][2];
int main() {
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i][0];
    cin >> arr[i][1];
  }
  int prev_index = 1;
  int total_count = 0;
  for (int i = 1; i <= n; i++) {
    total_count += (arr[i][0] - prev_index) % x;
    total_count += arr[i][1] - arr[i][0] + 1;
    prev_index = arr[i][1] + 1;
  }
  cout << total_count;
  return 0;
}
