#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int dp[100010] = {};
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a;
    cin >> b;
    if (n < b) {
      b = n;
    }
    for (int t = a; t <= b; i++) {
      dp[t]++;
    }
  }
  int mx = 0;
  for (int i = n; i > 0; i--) {
    if (dp[i] >= i) {
      mx = i;
      break;
    }
  }
  cout << mx << endl;
  return 0;
}
