#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
pair<int, int> a[5005], b[5005];
int n;
pair<bool, bool> dp[5005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].first, &a[i].second);
  sort(a + 1, a + n + 1);
  dp[1] = make_pair(true, true);
  for (int i = 2; i <= n; i++) {
    if (a[i].first >= a[i - 1].first && dp[i - 1].first) dp[i].first = true;
    if (a[i].first >= a[i - 1].second && dp[i - 1].second) dp[i].first = true;
    if (a[i].second >= a[i - 1].first && dp[i - 1].first) dp[i].second = true;
    if (a[i].second >= a[i - 1].second && dp[i - 1].second) dp[i].second = true;
  }
  if (dp[n].second)
    cout << a[n].second;
  else
    cout << a[n].first;
}
