#include <bits/stdc++.h>
using namespace std;
const int maxn = 5007;
pair<int, int> a[maxn];
int dp[maxn];
int n;
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[0] = 0;
  for (int i = 1; i <= n; ++i) {
    dp[i] = a[i].first;
    if (dp[i - 1] <= a[i].second) dp[i] = a[i].second;
  }
  cout << dp[n] << endl;
}
