#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  int temp;
  while (b > 0) {
    temp = b;
    b = a % b;
    a = temp;
  }
  return a;
}
int main() {
  int t, N, i;
  long long ans;
  scanf("%d", &N);
  ;
  pair<long long, long long> pa[N + 2];
  for (i = 1; i <= N; i++) {
    cin >> pa[i].first >> pa[i].second;
  }
  sort(pa + 1, pa + N + 1);
  long long last = min(pa[1].first, pa[1].second);
  bool flag = false;
  for (i = 2; i <= N; i++) {
    if (last > pa[i].second)
      last = pa[i].first;
    else
      last = pa[i].second;
  }
  cout << last;
  return 0;
}
