#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n, long long m) {
  if (m == 0) return n;
  return gcd(m, n % m);
}
long long lcm(long long n, long long m) { return n * m / gcd(n, m); }
long long fact(long long n) {
  if (n == 1 or n == 0)
    return 1;
  else
    return ((n % 1000000007) * (fact(n - 1) % 1000000007)) % 1000000007;
}
template <typename T>
int ext_gcd(T a, T b, T& x, T& y) {
  if (b == (T)0) {
    x = (T)1;
    y = (T)0;
    return a;
  }
  T x1, y1;
  int d = ext_gcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - (int(a / b)) * y1;
  return d;
}
bool prime(long long n) {
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
void solve(int testno) {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (auto& i : a) {
    cin >> i.first >> i.second;
  }
  sort(a.begin(), a.end());
  int last = a[0].second;
  for (int i = 1; i < n; i++) {
    if (a[i].second >= last)
      last = a[i].second;
    else
      last = a[i].first;
  }
  cout << last;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin.exceptions(ios::badbit | ios::failbit);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
  cerr << "\nProgram finished successfully\n";
  return 0;
}
