#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> pts[15000];
vector<pair<long long, long long> > invalid_ranges, current_range;
int main() {
  long long n, i, ma, mi, score;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> pts[i].first >> pts[i].second;
    ma = max(pts[i].first, pts[i].second);
    mi = min(pts[i].first, pts[i].second);
    if (i == n - 1) {
      score = ma + 1;
      if (ma > mi) {
        invalid_ranges.push_back(make_pair(mi + 1, ma));
      }
    } else {
      if (ma > mi + 1) {
        invalid_ranges.push_back(make_pair(mi + 1, ma - 1));
      }
    }
  }
  sort(invalid_ranges.begin(), invalid_ranges.end(),
       [](const pair<long long, long long> p1,
          const pair<long long, long long> p2) {
         return make_pair(p1.first, -p1.second) <
                make_pair(p2.first, -p2.second);
       });
  long long ct = 0;
  pair<long long, long long> last;
  for (i = 0; i < invalid_ranges.size(); i++) {
    if (i == 0) {
      current_range.push_back(invalid_ranges[i]);
      ct++;
    } else {
      last = current_range.back();
      if (invalid_ranges[i].first <= last.second &&
          invalid_ranges[i].second > last.second) {
        current_range[ct - 1].second = invalid_ranges[i].second;
      } else if (invalid_ranges[i].first > last.second) {
        current_range.push_back(invalid_ranges[i]);
        ct++;
      }
    }
  }
  long long invalid_scores = 0;
  for (pair<long long, long long> pa : current_range) {
    invalid_scores += (pa.second - pa.first + 1);
  }
  cout << score - invalid_scores << "\n";
  return 0;
}
