#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
int main() {
  int n;
  vector<int> num(100002, 0);
  cin >> n;
  int a, b;
  for (int i = (0); i <= (n - 1); ++i) {
    cin >> a >> b;
    for (int j = (a); j <= (b); ++j) {
      num[j]++;
    }
  }
  int ans = 0;
  for (int i = (1); i <= (n); ++i) {
    if (i - 1 <= num[i]) {
      ans = i - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
