#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n; cin >> n; vector> p(n); ll ans = 1; rep(i, n) cin >> p[i].first >> p[i].second; sort(p.begin(), p.end()); for (auto [l, r] : p) { if (ans < l) break; ans = max(ans, r); } cout << ans << endl; return 0; }