#include <bits/stdc++.h>
using namespace std;
pair<int, int> ar[10001];
void solve() {
  int n;
  scanf("%d", &n);
  ;
  for (int i = 0; i < n; i++) {
    scanf("%d", &ar[i].first);
    ;
    scanf("%d", &ar[i].second);
    ;
  }
  sort(ar, ar + n);
  int last = 0;
  for (int i = 0; i < n; i++) {
    if (ar[i].second >= last) {
      last = ar[i].second;
    } else {
      last = ar[i].first;
    }
  }
  cout << last << endl;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
