#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[5010];
int N;
int v[5010];
int main() {
  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> a[i].first >> a[i].second;
  sort(a + 1, a + N + 1);
  int ans = min(a[1].first, a[1].second);
  v[1] = ans;
  int ind;
  for (int i = 2; i <= N; ++i) {
    ind = i;
    for (int j = 1; j < i; ++j) {
      if (a[i].second < v[j]) ind = j;
    }
    if (ind == i)
      v[i] = a[i].second;
    else
      v[i] = a[i].first;
  }
  for (int i = 1; i <= N; ++i) ans = max(ans, v[i]);
  cout << ans << "\n";
  return 0;
}
