#include <bits/stdc++.h>
long long mod = 1e9 + 7;
using namespace std;
bool sec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long checkprime(long long N) {
  long long count = 0;
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      if (i * i == N)
        count++;
      else
        count += 2;
    }
  }
  if (count == 2)
    return 1;
  else
    return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<pair<long long, long long>> v(n);
  long long day = 0;
  for (int i = 0; i < (n); i++) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end());
  day = min(v[0].first, v[0].second);
  for (int i = (1); i <= (n - 1); i++) {
    if (min(v[i].first, v[i].second) >= day)
      day = min(v[i].first, v[i].second);
    else
      day = max(v[i].first, v[i].second);
  }
  cout << day;
}
