#include <bits/stdc++.h>
using namespace std;
const int inft = 1000000009;
const int MAXN = 1000006;
void solve() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int> > V(n);
  for (int i = 0; i < (n); ++i) {
    scanf("%d%d", &V[i].first, &V[i].second);
  }
  sort(V.begin(), V.end());
  int day = 0;
  for (typeof(V.begin()) it = V.begin(); it != V.end(); ++it) {
    if (day <= it->second)
      day = it->second;
    else
      day = it->first;
  }
  printf("%d\n", day);
}
int main() {
  int t = 1;
  for (int i = 0; i < (t); ++i) solve();
  return 0;
}
