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