#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
int n, a, b;
vector<pair<int, int> > v;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a, &b);
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  int ans = v[0].second;
  for (int i = 1; i < n; ++i) {
    if (ans > v[i].second) {
      if (v[i].first > ans) ans = v[i].first;
    } else
      ans = v[i].second;
  }
  printf("%d\n", ans);
  return 0;
}
