#include <bits/stdc++.h>
using namespace std;
int max(pair<int, int> a) { return (a.first > a.second ? a.first : a.second); }
int min(pair<int, int> a) { return (a.first < a.second ? a.first : a.second); }
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> score(n + 1);
  score[0] = make_pair(0, 0);
  for (int i = 1; i <= n; i++) {
    cin >> score[i].first >> score[i].second;
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (min(score[i]) >= max(score[i - 1])) {
      res += min(score[i]) - max(score[i - 1]) + 1;
      if (score[i].first == score[i].second) {
        res--;
      }
    }
  }
  if (score[n].first == score[n].second) res++;
  cout << res << "\n";
  return 0;
}
