#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << (x) << endl
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define irep(i, a, b) for (int i = a; i >= (int)(b); i--)
#define inbounds(x, l, r) ((l) <= (x) && (x) <= (r))
#define L0(res...) [&](){ return res; }
#define L1(res...) [&](auto const & x){ return res; }
#define L2(res...) [&](auto const & x, auto const& y){ return res; }
template<class T> inline void chmin(T & a, const T b){ if (a > b) a = b; }
template<class T> inline void chmax(T & a, const T b){ if (a < b) a = b; }
const int oo = 0x3f3f3f3f3f3f3f3f;
struct OnlineMatching {
int n = 0, m = 0;
vector<int> vis, match, dist;
vector<vector<int>> g;
vector<int> last;
int t = 0;
OnlineMatching(int n_, int m_) : n(n_), m(m_),
vis(n, 0), match(m, -1), dist(n, n+5), g(n), last(n, -1)
{}
void add(int a, int b) {
g[a].pb(b);
}
bool kuhn(int a) {
vis[a] = t;
for(const int b: g[a]) {
int c = match[b];
if (c == -1) {
match[b] = a;
return true;
}
if (last[c] != t || (dist[a] + 1 < dist[c]))
dist[c] = dist[a] + 1, last[c] = t;
}
for (const int b: g[a]) {
int c = match[b];
if (dist[a] + 1 == dist[c] && vis[c] != t && kuhn(c)) {
match[b] = a;
return true;
}
}
return false;
}
bool can_match(int a) {
t++;
last[a] = t;
dist[a] = 0;
return kuhn(a);
}
};
struct CC {
vector<int> v;
CC(vector<int> & a) : v(a) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
int get(int x) {
return lower_bound(all(v), x) - v.begin();
}
};
void solve() {
int n; cin >> n;
vector<int> day1(n), day2(n);
vector<int> days(2*n);
rep(i, 0, n) {
cin >> day1[i];
cin >> day2[i];
days[i] = day1[i];
days[n+i] = day2[i];
}
CC cc(days);
OnlineMatching matching(cc.v.size(), n);
rep(i, 0, n) {
matching.add(cc.get(day1[i]), i);
matching.add(cc.get(day2[i]), i);
}
int ans = 0;
rep(i, 0, cc.v.size()) {
if (matching.can_match(i)) ans++;
if (ans == n) {
cout << cc.v[i] << endl;
return;
}
}
cout << -1 << endl;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
for (int i = 0; i < t; i++) {
solve();
}
return 0;
}
561. Array Partition I | 1374. Generate a String With Characters That Have Odd Counts |
1822. Sign of the Product of an Array | 1464. Maximum Product of Two Elements in an Array |
1323. Maximum 69 Number | 832. Flipping an Image |
1295. Find Numbers with Even Number of Digits | 1704. Determine if String Halves Are Alike |
1732. Find the Highest Altitude | 709. To Lower Case |
1688. Count of Matches in Tournament | 1684. Count the Number of Consistent Strings |
1588. Sum of All Odd Length Subarrays | 1662. Check If Two String Arrays are Equivalent |
1832. Check if the Sentence Is Pangram | 1678. Goal Parser Interpretation |
1389. Create Target Array in the Given Order | 1313. Decompress Run-Length Encoded List |
1281. Subtract the Product and Sum of Digits of an Integer | 1342. Number of Steps to Reduce a Number to Zero |
1528. Shuffle String | 1365. How Many Numbers Are Smaller Than the Current Number |
771. Jewels and Stones | 1512. Number of Good Pairs |
672. Richest Customer Wealth | 1470. Shuffle the Array |
1431. Kids With the Greatest Number of Candies | 1480. Running Sum of 1d Array |
682. Baseball Game | 496. Next Greater Element I |