#include <bits/stdc++.h>
using namespace std;
vector<int> primes, check(1e6, 0);
void seive() {
  for (int i = 2; i * i <= 1e9; i++) {
    if (check[i] == 0) {
      check[i] = 1;
      primes.push_back(i);
      for (int j = i * i; j <= 1e6; j += i) check[j] = 1;
    }
  }
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const unsigned int mod = 1000000007;
const unsigned int mod2 = 998244353;
int64_t power(int a, int p) {
  int64_t res = 1;
  while (p) {
    if (p % 2 == 0) {
      a = a * 1ll * a % mod;
      p /= 2;
    } else {
      res = res * 1ll * a % mod;
      p--;
    }
  }
  return res;
}
int64_t fact(int n) {
  int64_t res = 1;
  for (int i = 1; i <= n; i++) {
    res = res * 1ll * i % mod;
  }
  return res;
}
int C(int n, int k) {
  return fact(n) * 1ll * power(fact(k), mod - 2) % mod * 1ll *
         power(fact(n - k), mod - 2) % mod;
}
signed main() {
  ;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int64_t n;
  cin >> n;
  pair<int, int> p[n + 1];
  for (int i = 1, a, b; i <= n; i++) {
    cin >> a >> b;
    p[i].first = a, p[i].second = b;
  }
  p[0] = {0, 0};
  sort(p + 1, p + n + 1);
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    if (p[i].second < p[i].first and p[i].second >= ans)
      ans = p[i].second;
    else if (p[i].first >= ans)
      ans = p[i].first;
  }
  cout << ans;
}
