#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<cstring>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<deque>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<string>
#include<sstream>
#include<climits>
#include<chrono>
#include<random>
#include<unordered_set>
#include<unordered_map> 
#include<ctype.h>
#include<cassert>
#include<numeric>
#include<functional>
using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef long double ldb; typedef double db;typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef pair<ll, int> pli;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Debug cout<<"\nRight Here\n";
const double Pi = acos(-1.0); constexpr int inf = 1 << 29, Mod = 1e9 + 7, N = 1e5 + 3; constexpr ll INF = 1ll << 60;
ll qpow(ll a, ll b, ll mod = Mod, ll ans = 1) {
	for (; b; b >>= 1, a = (a * a + mod) % mod)if (b & 1)ans = (ans * a + mod) % mod;
	return ans;
}
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }; ll lcm(ll a, ll b) { return a * b / (gcd(a, b)); }
pii EXgcd(int x, int y) {        //return.first ny
	if (!y) { return { 1,0 }; }pii a = EXgcd(y, (x + y) % y);
	return { a.second, a.first - a.second * (x / y) };
}
inline bool Ezisprime(const int n) {
	if (n <= 1)return 0; if (n <= 3)return 1;
	vector<int> ezp{ 5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 };
	for (int i = 0; i < ezp.size(); i++)if (n == ezp[i])return 1;
	for (int i = 2; i <= sqrt(n); i++)if (n % i == 0)return 0;
	return 1;
}
pll Fib(ll n) {
	if (n == 0) return { 0, 1 };
	auto p = Fib(n >> 1);
	ll c = p.first * ((p.second) << 1 - p.first), d = p.first * p.first + p.second * p.second;
	if (n & 1)return { d, c + d }; else return { c, d };
}
inline vector<ll> EuSieve(const ll& n) {
	vector<ll> prime; vector<bool>is_prime(n + 1, 1);
	for (ll i = 2; i <= n; ++i) {
		if (is_prime[i])prime.emplace_back(i);
		for (auto& p : prime) {
			if (i * p > n)break;
			is_prime[i * p] = 0;
			if (i % p == 0)break;
		}
	}
	return prime;
}
inline ll Digsum(ll n, ll ans = 0) {
	for (; n; n /= 10)ans += n % 10;
	return ans;
}
inline void modize(ll& n, const ll add, const ll mod = Mod) { n = ((n + add) % mod + mod) % mod; }
inline bool cmp(const pii a, const pii b) {  //default more and more larger 
	return a.second < b.second;
}
//partial_sum(begin,end,place,minus<int>()) adjacent_differece(begin,end,place) 
//count(begin(),end(),char=='x') count_if(begin(),end(),boolcmp) vector<int> p(n);iota(p.begin(), p.end(), 0);
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Code follows ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\\



int main()
{
	ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);

	int n; cin >> n;
	vector<vector<ll>>a(n, vector<ll>(5));
	for (auto& i : a)for (auto& j : i)cin >> j;
	int l = 0, r = 1e9 + 1;
	auto check = [&](int x)->bool
	{
		set<int>s;
		for (auto i : a)
		{
			int bit = 0;
			for (auto j : i)
			{
				bit <<= 1;
				bit |= j >= x;
			}
			s.insert(bit);
		}
		for (auto i : s)for (auto j : s)for (auto k : s)if ((i | j | k) == 31)return 1;
		return 0;
	};
	while (r - l > 1)
	{
		int mid = (l + r) >> 1;
		(check(mid) ? l : r )= mid;
//		cout << "l= " << l << " r= " << r << '\n';
	}
	cout << l << '\n';

}
/*


*/




#include <bits/stdc++.h>
using namespace std;
//-(smallstar))---- :]

#define int long long
#define ll long long
#define ld long double
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define fr(i, n) for (int i = 0, _##i = (n); i < _##i; ++i)
#define fd(i, n) for (int i = (n); --i >= 0;)
#define frr(i, l, r) for (int i = (l), _##i = (r); i < _##i; ++i)
#define fdd(i, l, r) for (int i = (r), _##i = (l); --i >= _##i;)
#define repi(i, a) for (__typeof((a).begin()) i = (a).begin(), _##i = (a).end(); i != _##i; ++i)
#define dwni(i, a) for (__typeof((a).rbegin()) i = (a).rbegin(), _##i = (a).rend(); i != _##i; ++i)
#define pi pair<ll, ll>
#define tii tuple<ll, ll, ll>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define vi vector<ll>
#define vii vector<pi>
#define eb emplace_back
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define sz(a) (ll)((a).size())
#define filla(a, n, val)       \
    for (ll i = 0; i < n; i++) \
        a[i] = val;
#define all(o) (o).begin(), (o).end()
#define rall(o) (o).rbegin(), (o).rend()
#define bitcount __builtin_popcountll
#define nl cout << "\n"
#define ns cout << " "
#define o2(a, b) cout << a << " " << b
#define o(a) cout << a
#define ppr(a) cout << a.first << " " << a.second
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define debugvi(a)                           \
    for (int idx = 0; idx < a.size(); idx++) \
    {                                        \
        cerr << #a << "[" << idx << "]: ";   \
        for (auto i : a[idx])                \
            cerr << i << " ";                \
        cerr << ' ';                         \
        cerr << '\n';                        \
    }
#define debugpp(a)                                         \
    cerr << #a << ": ";                                    \
    for (auto i : a)                                       \
        cerr << "(" << i.first << "," << i.second << ") "; \
    cerr << '\n';
#define EPSILON 1e-9

void takeInput(vi &a, int n)
{
    ll l;
    for (int i = 0; i < n; i++)
    {
        cin >> l;
        a.pb(l);
    }
}

const ll MOD = 1000000007;
const ll LIM = 200005;
const ll BITS = 31;
const ll inf = 1e16;
// vector<vector<int>> vec( n , vector<int> (m, 0));

void solve()
{
    int n;
    cin >> n;

    int ans = INT_MAX;
    vector<pair<int, int>> a;
    vector<pair<int, int>> b;
    while (n--)
    {
        int x, y;
        cin >> x >> y;
        a.push_back({x, n});
        b.pb({y, n});
    }
    sort(all(a));
    sort(all(b));
    int minn = INT_MAX;
    if (a[0].second != b[0].second)
    {
        cout << max(a[0].first, b[0].first);

        return;
    }
    else
    {
        minn = a[0].first + b[0].first;
        minn = min(minn, max(a[0].first, b[1].first));
        minn = min(minn, max(a[1].first, b[0].first));
    }
    cout << minn;
}

signed main()
{
    fastio;
    int t;
    t = 1;
    //  cin >> t;
    fr(i, t)
    {
        solve();
    }
}