#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10 + 10000;
const int INF = int(1e9);
int n;
pair<int, int> a[MAXN];
int main() {
  cin >> n;
  for (int i = (0), _b = (n); i < n; ++i) cin >> a[i].first >> a[i].second;
  sort(a, a + n);
  int cur = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i].second >= cur)
      cur = a[i].second;
    else
      cur = a[i].first;
  }
  cout << cur;
  return 0;
}
