#include<bits/stdc++.h>
#include<tuple>
typedef long long ll;
#define INF 99999999999999
#define mod 1000000007
#define eps 1e-9
using namespace std;
ll n,h,l=1,r=1000000000;
ll val[10][3005];
ll ans,res;
set<ll>bsk;
map<ll,ll>cnt;
bool check(ll x){
    bsk.clear();
    ll can=0;
    //cout<<"x="<<x<<endl;
    for(ll i=1;i<=n;i++){
        ll res=0;
        for(ll j=0;j<=4;j++)
            if(val[j][i]>=x)
                res+=1<<j;
        //cout<<res<<endl;
        bsk.insert(res);
    }
    for(auto i:bsk)
        for(auto j:bsk)
            for(auto k:bsk){
                if((i|j|k)==31)
                    can=1;
                }
    return can;
}
int main(){
    ios::sync_with_stdio(0);
    auto st=clock();
    cin>>n;
    srand(time(NULL));
    for(ll i=1;i<=n;++i)
        for(ll j=0;j<=4;++j)
            cin>>val[j][i];
    while(l<=r){
        ll mid=(l+r)>>1;
        if(check(mid))
            ans=mid,l=mid+1;
        else
            r=mid-1;
    }
    cout<<ans<<endl;
    return 0;
}
#include <bits/stdc++.h>
#define li long int
#define lli long long 
#define pb push_back
#define fi first
#define se second
#define si size()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define lb lower_bound
#define ub upper_bound
#define BS binary_search
#define pll pair < lli, lli >
#define pii pair < int, int>
#define vi vector < int >
#define vvi vector < vector < int > >
#define vlli vector < lli >
#define all(x) x.begin(), x.end()
using namespace std;  

int main()
{
    fastio;
    int mid,ans=1,n,i,l,r,j,f=0,k;
    cin>>n;
    vvi v(n, vi(5)), arr(n, vi(5));
    for(i=0;i<n;i++)    cin>>v[i][0]>>v[i][1]>>v[i][2]>>v[i][3]>>v[i][4];
    l=1, r=1e9;
    while(l<=r)
    {
        
        arr=v;
        mid=(l+r)/2;
        f=0;
        set<int> s; 
        for(i=0;i<n;i++)
        {
            for(j=0;j<5;j++)    
            {
                if(arr[i][j]<mid)   arr[i][j]=0;
                else                arr[i][j]=1;
            }
            int zz=arr[i][0]*16+arr[i][1]*8+arr[i][2]*4+arr[i][3]*2+arr[i][4];
            if(zz==31)  {f=1;}
            s.insert(zz);
        }
        if(f)
        {
            l=mid+1;
            ans=max(ans, mid);
            continue;
        }
        vi pos;
        for(auto ii:s)  pos.pb(ii);
        int sz=s.size();
        if(sz==1)
        {
            r=mid-1;    continue;
        }
        if(sz==2)
        {
            if((pos[0]|pos[1])==31)   
            {
                l=mid+1;ans=max(ans, mid);
            }
            else    r=mid-1;
            continue;
        }
        for(i=0;i<sz-2;i++)
        {
            for(j=i+1;j<sz-1;j++)
            {
                for(k=j+1;k<sz;k++)
                {
                    if((pos[i]|pos[j]|pos[k])==31){f=1; break;}
                }
            }
        }
        if(f)  { l=mid+1;ans=max(ans, mid);}
        else    r=mid-1;
    }
    cout<<ans<<"\n";
}