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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define codeWizard      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define testCase(tc)    while(tc--)
#define vi              vector<int>
#define vvi             vector<vi>
#define pi              pair<int,int>
#define int             long long
#define lb              lower_bound
#define ub              upper_bound
#define mod             1000000007
//#define mod           998244353
#define ff              first
#define ss              second
#define inf             (int)1e17
#define ninf            -inf
#define endl            "\n"
#define fill(a,b)       memset(a,b,sizeof(a))
#define all(v)          v.begin(),v.end()                               //codeWizard
int LCM(int a, int b) {return (a * b) / __gcd(a, b);}

void init_code() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int n;
vvi player;
bool check(int x){
    set<int> st;

    for(auto k:player){
        int bit=0;
        int i=0;
        for(auto i:k){
            bit <<= 1;
                bit |= i >= x;

        }
        st.insert(bit);
    }

    for(auto x:st){
        for(auto y:st){
            for(auto z:st){
                if((x|y|z)==31)
                    return true;
            }
        }
    }
    return false;
}
void solve(){
   cin>>n;
   for(int i=1;i<=n;i++){
    vector<int> temp(5);
    for(int j=0;j<5;j++)
        cin>>temp[j];
    player.push_back(temp);
   }
   int low=1,high=1000000001;
   int ans=0;
   while(high>low+1){
    //cout<<low<<" "<<high<<endl;
    int mid=(low+high)/2;
    if(check(mid)){
        low=mid;
    }
    else
        high=mid;
   }
   cout<<low<<endl;
}
signed main()
{
    codeWizard;
    init_code();
    int tc = 1;
    //cin >> tc;
    int num=1;
    testCase(tc) {
        //cout<<"Case #"<<num<<": ";

        num++;
        solve();
    }

    //cout << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;

}


#include<bits/stdc++.h>
using namespace std;
int mod=1e9+7;
const int N=2e5+5;
int32_t main()
{
    int ans=0;
    int n;
    cin>>n;
    vector<vector<int>  > a(n,vector<int> (5));
    vector<vector<int>  > dp(5);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<5;j++)
        {
            cin>>a[i][j];
            dp[j].push_back(a[i][j]);
        }
    }
    for(int i=0;i<5;i++)
    {
        sort(begin(dp[i]),end(dp[i]),greater<int> ());
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            int ind;
            int mini=1e9;
            for(int k=0;k<5;k++)
            {
                if(max(a[i][k],a[j][k])<mini)
                {
                    ind=k;
                    mini=max(a[i][k],a[j][k]);
                }
            }
            int val=1e9;
            for(int k=0;k<5;k++)
            {
                if(k!=ind)
                val=min(val,max(a[i][k],a[j][k]));
            }
            if(dp[ind][0]!=a[i][ind]&&dp[ind][0]!=a[j][ind])
            val=min(val,dp[ind][0]);
            else if(dp[ind][1]!=a[i][ind]&&dp[ind][1]!=a[j][ind])
            val=min(val,dp[ind][1]);
            else 
            val=min(val,dp[ind][2]);
            ans=max(ans,val);
        }
    }
    cout<<ans<<endl;
}