/* -*- coding: utf-8 -*- * * 3797.cc: No.3797 Express Elevators and Emergency Stairs - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ using pii = pair; /* global variables */ int as[MAX_N], bs[MAX_N]; pii ps[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d%d", as + i, bs + i); for (int i = 0; i < n; i++) ps[i] = {as[i] ,bs[i]}; sort(ps, ps + n); int x = 1; for (int i = 0; i < n; i++) { auto [ai, bi] = ps[i]; if (ai <= x) x = max(x, bi); else break; } printf("%d\n", x); return 0; }