#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, ls = 1;
  cin >> n >> m;
  long long a[n][2];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < 2; j++) cin >> a[i][j];
  long long total = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i][0] == 1) {
      total += a[i][1];
      ls += a[i][1];
    } else {
      total += (a[i][0] - ls) % m;
      total += a[i][1] - a[i][0] + 1;
      ls = ++a[i][1];
    }
  }
  cout << total;
  return 0;
}
