#include <bits/stdc++.h>
using namespace std;
const int maxn = 12333;
pair<int, int> a[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &a[i].first, &a[i].second);
  sort(a + 1, a + n + 1);
  int k = 0;
  for (int i = 1; i <= n; ++i) k = k <= a[i].second ? a[i].second : a[i].first;
  printf("%d\n", k);
  return 0;
}
