#include <bits/stdc++.h>
using namespace std;
const int N = 5009;
pair<int, int> p[N];
int dp[N];
int main() {
  int i, j, t, n;
  while (cin >> n) {
    for (i = 1; i <= n; ++i) {
      cin >> p[i].first >> p[i].second;
    }
    p[0] = make_pair(0, 0);
    sort(p + 1, p + n + 1);
    int ans = 0;
    for (i = 1; i <= n; ++i) {
      if (p[i].second >= ans) {
        ans = p[i].second;
      } else {
        ans = p[i].first;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
