#include<bits/stdc++.h>
using namespace std;
#define N 10005
bitset<N>p[5],f[3];
int n,i,l,r,cnt,mid,a[N][10],c[10],fl,b[5][5],e[10];
bool check(){
	int i;
	for(i=1;i<=n;++i)f[0][i]=f[1][i]=f[2][i]=1;
	for(i=0;i<5;++i){
		f[e[i]]&=p[i];
	}
	if(f[0].count()&&f[1].count()&&f[2].count())return 1;
	return 0;
}
void dfs(int now){
	if(now==5){fl|=check();return ;}
	e[now]=0;dfs(now+1);e[now]=1;dfs(now+1);e[now]=2;dfs(now+1);
}
int check(int x){
	for(int i=0;i<5;++i){
		for(int j=1;j<=n;++j){
			if(a[j][i]>=x)p[i][j]=1;else p[i][j]=0;
		}
	}
	fl=0;dfs(1);if(fl)return 1;return 0;
}
int main(){
	cin>>n;
	for(i=1;i<=n;++i)cin>>a[i][0]>>a[i][1]>>a[i][2]>>a[i][3]>>a[i][4];
	l=0;r=1e9;
	while(l<r){
		mid=r-(r-l>>1);
		if(check(mid))l=mid;
		else r=mid-1;
	} cout<<l;
}
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#include <math.h>
#define vi v(n) vector<ll> v(n);
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main(){
    IOS
    ll n;
    cin>>n;
    ll dp[n+1][3][35];
    fo(i,n+1){
        fo(j,3){
            fo(k,35){
                dp[i][j][k]=0;
            }
        }
    }
    ll a,b,c,d,e;
    FOR(i,1,n){
        cin>>a>>b>>c>>d>>e;
        vector<ll> myVals{a,b,c,d,e};
        fo(j,3){
            fo(k,32){
                ll val=dp[i-1][j][k];
                fo(l,32){
                    if(k|l==k){
                        if(j==0){
                            if(l!=k) continue;
                            ll my=10000000000000;
                            fo(m,5){
                                if(l&(1<<m)){
                                    my=min(my,myVals[m]);
                                }
                            }
                            if(my==10000000000000) my=0;
                            val=max(val,my);

                        }
                        else if(i>=j+1){
                            
                            ll my=10000000000000;
                            fo(m,5){
                                if(l&(1<<m)){
                                    my=min(my,myVals[m]);
                                }
                            }
                            if(my==10000000000000) my=0;
                            my=min(my,dp[i-1][j-1][l^k]);
                            val=max(val,my);
                        }
                    }
                }
                dp[i][j][k]=val;
            }
        }
    }
   // dbg(dp[1][0][1]);
    cout<<dp[n][2][31]<<endl;
   
}