#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > F;
int solve(int low, int high, int ans);
int main() {
  int n;
  cin >> n;
  for (int i = 0, a, b; i < n; i++) {
    cin >> a >> b;
    F.push_back(make_pair(a, b));
  }
  cout << solve(0, n, 0) << endl;
  return 0;
}
int solve(int low, int high, int ans) {
  int mid = (low + high) / 2, num = 0;
  if (high <= low || mid == ans) return ans;
  for (int i = 0; i < F.size(); i++)
    if (mid + 1 >= F[i].first && mid + 1 <= F[i].second) num++;
  if (mid <= num) return solve(mid, high, mid);
  return solve(low, mid, ans);
}
