#include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> a[5010];
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++) scanf("%d%d", &a[i].first, &a[i].second);
    sort(a, a + n);
    int pre = 0;
    for (int i = 0; i < n; i++) {
      int min_val = min(a[i].first, a[i].second);
      int max_val = max(a[i].first, a[i].second);
      if (min_val >= pre)
        pre = min_val;
      else
        pre = max_val;
    }
    printf("%d\n", pre);
  }
  return 0;
}
