#include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> a[5005];
int main() {
  int i, ans;
  cin >> n;
  for (i = 0; i < (n); i++) cin >> a[i].first >> a[i].second;
  sort(a, a + n);
  ans = 0;
  for (i = 0; i < (n); i++) {
    if (a[i].first < ans)
      ans = a[i].second;
    else if (a[i].second < ans)
      ans = a[i].first;
    else
      ans = min(a[i].first, a[i].second);
  }
  cout << ans << endl;
  return 0;
}
