#include <bits/stdc++.h>
using namespace std;
int prime_arr[1000001];
unordered_map<int, int> prime_map;
int toInt(string str) {
  int num;
  stringstream ss(str);
  ss >> num;
  return num;
}
string toString(int n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
string trimLeft(string str, char c) {
  for (int i = 0; i < str.length(); i++) {
    if (str[i] != c) {
      return str.substr(i);
    }
  }
  return "";
}
string trimRight(string str, char c) {
  for (int i = str.length() - 1; i >= 0; i--) {
    if (str[i] != c) {
      return str.substr(0, i + 1);
    }
  }
  return "";
}
string trim(string str, char c) {
  str = trimLeft(str, c);
  return trimRight(str, c);
}
void collectPrimes() {
  for (int i = 2; i < 1000001; i++) {
    if (!prime_arr[i]) {
      for (int j = i + i; j < 1000001; j += i) {
        prime_arr[j] = 1;
      }
      prime_map[i] = 1;
    }
  }
}
string replaceAll(string str, string src, string dest) {
  string temp = str;
  string result = "";
  int srcLen = src.length();
  if (srcLen) {
    int startPos = 0;
    while ((startPos = temp.find(src, startPos)) != string::npos) {
      temp.replace(startPos, srcLen, dest);
    }
  }
  return temp;
}
int getNum(char c) { return c - '0'; }
char convertToNum(int n) { return n + '0'; }
int l[100001], r[100001];
int main() {
  int result = 0;
  int n, x;
  cin >> n >> x;
  cin >> l[0] >> r[0];
  result += (r[0] - l[0] + 1) + ((l[0] - 1) % x);
  for (int i = 1; i < n; i++) {
    cin >> l[i] >> r[i];
    result += (r[i] - l[i] + 1) + ((l[i] - r[i - 1] - 1) % x);
  }
  cout << result << endl;
  return 0;
}
