#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
bool palindrom(string s) {
  string ss = "";
  for (int i = 0; i <= s.size() - 1; i++) ss = s[i] + ss;
  return ss == s;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  pair<int, int> p[n];
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p, p + n);
  int ans = -1;
  for (int i = 0; i < n; i++) {
    if (ans <= p[i].second) {
      ans = p[i].second;
    } else
      ans = p[i].first;
  }
  cout << ans;
  return 0;
}
