#include <bits/stdc++.h>
using namespace std;
struct examen {
  int a;
  int b;
  const bool operator<(examen e) const {
    if (a == e.a) return b < e.b;
    return a < e.a;
  }
} exam[100000];
int main() {
  int n, crt = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &exam[i].a, &exam[i].b);
  }
  sort(exam, exam + n);
  for (int i = 0; i < n; ++i) {
    if (min(exam[i].a, exam[i].b) >= crt)
      crt = min(exam[i].a, exam[i].b);
    else
      crt = max(exam[i].a, exam[i].b);
  }
  printf("%d", crt);
}
