#include <bits/stdc++.h>
const int MOD = 1000000007;
const int INF = 1000000000;
using namespace std;
const double eps = 1e-9;
const int inf = 1e9;
int n;
int syaku[100010];
int main(int argc, char const* argv[]) {
  cin >> n;
  memset(syaku, 0, sizeof(syaku));
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    syaku[l]++;
    syaku[r]--;
  }
  for (int i = 1; i < 100010; i++) {
    syaku[i] += syaku[i - 1];
  }
  int ans = 0;
  for (int i = n + 1; i >= 0; i--) {
    if (i - syaku[i] == 1) {
      ans = syaku[i];
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
