#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<vector<int> > p(n, vector<int>(100001));
  int ma = 0;
  for (int(i) = (0); (i) < (int)(n); ++(i)) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    ma = max(ma, b);
    for (int j = a; j <= b; ++j) {
      p[i][j]++;
    }
  }
  int ans = 0;
  for (int(i) = (0); (i) < (int)(ma); ++(i)) {
    int t = 0;
    for (int(j) = (0); (j) < (int)(n); ++(j)) {
      t += p[j][i];
    }
    if (i <= t) {
      ans = i;
    }
  }
  cout << ans << endl;
}
