#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[5010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[i] = make_pair(x, y);
  }
  sort(a + 1, a + n + 1);
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    if (a[i].second >= ans) {
      ans = a[i].second;
    } else {
      ans = a[i].first;
    }
  }
  printf("%d\n", ans);
  return 0;
}
