// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#include<list>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<double,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
typedef ll Def;

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	vvi in(n,vi(5));
	rep(i,n)rep(j,5)cin>>in[i][j];

	int l=0,r=1000000010;
	while(r-l>1){
		int h=(l+r)/2;
		vi w(32);
		w[0]=1;
		vi b(n);
		rep(i,n){
			int a=0;
			rep(j,5)if(h<=in[i][j])a|=1<<j;
			w[a]++;
			b[i]=a;
		}
		bool H=false;
		rep(i,n)rep(j,i){
			int a=b[i]|b[j];
			a=31-a;
			if(w[a])H=true;
		}
		if(H)l=h;
		else r=h;
	}
	cout<<l<<endl;
}

#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 10;
const int s = (1 << 5) - 1;
const int N = 5;
int a[maxn][5];
int n;
int f[s + 10], g[s + 10], h[10][s + 10], fhat[10][s + 10], ghat[10][s + 10], fog[s + 10];
bool check(int x)
{
	memset(f, 0, sizeof f);
	memset(g, 0, sizeof g);
	memset(h, 0, sizeof h);
	memset(fhat, 0, sizeof fhat);
	memset(ghat, 0, sizeof ghat);
	
	for(int i = 1; i <= n; ++i)
	{
		int cur = 0;
		for(int j = 0; j < 5; ++j)
			if(a[i][j] >= x)
				cur |= 1 << j;
		f[cur] = 1;
	}
	for(int i = s; i; --i)
		for(int j = 0; j < 5; ++j)
			if(i & (1 << j))
				f[i ^ (1 << j)] |= f[i];
	for(int i = 0; i <= s; ++i) g[i] = f[i];
	
	for(int mask = 0; mask < (1 << N); mask++) {
	    fhat[__builtin_popcount(mask)][mask] = f[mask];
	    ghat[__builtin_popcount(mask)][mask] = g[mask];
	}
	
	// Apply zeta transform on fhat[][] and ghat[][]
	for(int i = 0; i < N; i++) {
	    for(int j = 0; j < N; j++) {
	        for(int mask = 0; mask < (1 << N); mask++) {
	            if((mask & (1 << j)) != 0) {
	                fhat[i][mask] += fhat[i][mask ^ (1 << j)];
	                ghat[i][mask] += ghat[i][mask ^ (1 << j)];
	            }
	        }
	    }
	}
	
	// Do the convolution and store into h[][] = {0}
	for(int mask = 0; mask < (1 << N); mask++) {
	    for(int i = 0; i < N; i++) {
	        for(int j = 0; j <= i; j++) {
	            h[i][mask] += fhat[j][mask] * ghat[i - j][mask];
	        } 
	    }
	}
	
	// Apply inverse SOS dp on h[][]
	for(int i = 0; i < N; i++) {
	    for(int j = 0; j < N; j++) {
	        for(int mask = 0; mask < (1 << N); mask++) {
	            if((mask & (1 << j)) != 0) {
	                h[i][mask] -= h[i][mask ^ (1 << j)];
	            }
	        }
	    }
	}
	for(int mask = 0; mask < (1 << N); mask++) fog[mask] = h[__builtin_popcount(mask)][mask];	
	for(int i = 0; i <= s; ++i)
		if(f[i] && fog[s - i])
			return 1;
	return 0;	
}			
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		for(int j = 0; j < 5; ++j)
			scanf("%d", &a[i][j]);
	int l = 1, r = 1e9;
	while(l <= r)
	{
		int mid = l + r >> 1;
		if(check(mid)) l = mid + 1;
		else r = mid - 1;
	}
	printf("%d\n", r);
	return 0;
}