#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
const int INF = 1e9;
const long long MOD = 1e9 + 7;
int n;
pair<int, int> mas[MAXN];
void solve(int n) {
  for (int i = 0; i < n; i++) {
    cin >> mas[i].first >> mas[i].second;
  }
  sort(mas, mas + n);
  int curr = 0;
  for (int i = 0; i < n; i++) {
    curr = (mas[i].second >= curr) ? mas[i].second : mas[i].first;
  }
  cout << curr;
}
int main() {
  ios_base::sync_with_stdio(false);
  while (cin >> n) {
    solve(n);
  }
}
