#include <bits/stdc++.h>
using namespace std;
struct aaa {
  int a, b;
};
int n, last;
aaa m[10000];
bool cmp(aaa a, aaa b) { return (a.a < b.a || a.a == b.a && a.b < b.b); }
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> m[i].a >> m[i].b;
  sort(m, m + n, cmp);
  last = m[0].b;
  for (int i = 1; i < n; ++i)
    if (m[i].b >= last)
      last = m[i].b;
    else
      last = m[i].a;
  cout << last << '\n';
  return 0;
}
