#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int N;
int a[100005];
int b[100005];
int imos[100005];
bool ok(int m) { return imos[m] >= m - 1; }
int main() {
  cin >> N;
  for (int i = 0; i < (int)(N); i++) cin >> a[i] >> b[i];
  for (int i = 0; i < (int)(N); i++) {
    ++imos[a[i]];
    --imos[b[i] + 1];
  }
  for (int i = 0; i < (int)(100005); i++)
    if (i) imos[i] += imos[i - 1];
  int ans = 0;
  for (int i = 0; i < (int)(N + 1); i++)
    if (ok(i)) ans = i;
  cout << ans - 1 << endl;
  return 0;
}
