#include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> x[5050];
void iWork() {
  cin >> n;
  int i;
  for (i = 1; i <= n; i++) cin >> x[i].first >> x[i].second;
  sort(x + 1, x + n + 1);
  int ans = 0;
  for (i = 1; i <= n; i++)
    if (x[i].second >= ans)
      ans = x[i].second;
    else
      ans = x[i].first;
  cout << ans << endl;
}
int main() {
  iWork();
  return 0;
}
