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