#include<bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,n) for(int i=0;i<n;i++)

int N;
int A[3010], B[3010], C[3010], D[3010], E[3010];
bool dp[3010][100][10];

bool unit(int mid)
{
    memset(dp, false, sizeof(dp));

    rep(i, N)
    {
        int bit = 0;
        bit |= (1LL << 0) * (A[i] >= mid);
        bit |= (1LL << 1) * (B[i] >= mid);
        bit |= (1LL << 2) * (C[i] >= mid);
        bit |= (1LL << 3) * (D[i] >= mid);
        bit |= (1LL << 4) * (E[i] >= mid);
        dp[0][0][0] = true;
        rep(j, (1LL << 5))rep(k, 3 + 1)
        {
            dp[i + 1][j][k] |= dp[i][j][k];
            dp[i + 1][j | bit][k + 1] |= dp[i][j][k];
        }
    }

    rep(i, 4)if(dp[N][(1LL << 5) - 1][i])return true;
    return false;
}

signed main()
{
    cin >> N;
    rep(i, N)cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i];

    int l = 0, r = 1e10;
    rep(_, 100)
    {
        int mid = (l + r) / 2;
        if(unit(mid))l = mid;
        else r = mid;
    }

    cout << l << endl;

    return 0;
}
#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';

}
/*


*/



