#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const long long MX = 2e6 + 10;
const long long dx[8] = {1, 0, -1, 0, 1, 1, -1, -1},
                dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
bool TC = 0;
void test_case() {
  long long N, X;
  cin >> N >> X;
  pair<long long, long long> A[N];
  for (long long i = 0; i < N; i++) cin >> A[i].first >> A[i].second;
  long long res = 0;
  long long last = 1;
  for (long long i = 0; i < N; i++) {
    res += (A[i].first - last) % X;
    res += (A[i].second - A[i].first + 1);
    last = A[i].second + 1;
  }
  cout << res;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (TC) {
    long long T;
    cin >> T;
    while (T--) test_case();
  } else
    test_case();
  return 0;
}
