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