#include <bits/stdc++.h>
using namespace std;
pair<int, int> exam[5050];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    exam[i] = make_pair(a, b);
  }
  sort(exam, exam + n);
  int now = 0;
  for (int i = 0; i < n; i++)
    if (exam[i].second < now)
      now = exam[i].first;
    else
      now = exam[i].second;
  cout << now << endl;
  return 0;
}
