#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <numeric>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<vector<int>> ability(N, vector<int>(5));
    vector<int> max_ability(5);
    for (int i=0; i<N; i++){
        for (int j=0; j<5; j++){
            cin >> ability.at(i).at(j);
            max_ability.at(j) = max(ability.at(i).at(j), max_ability.at(j));
        }
    }
    int ans = 0;
    for (int i=0; i<N-1; i++){
        for (int j=i+1; j<N; j++){ //候補者i,j
            vector<int> candidate(5);
            for (int k=0; k<5; k++) candidate.at(k) = max(ability.at(i).at(k), ability.at(j).at(k));
            vector<int> order(5);
            iota(order.begin(), order.end(),0); 
            sort(order.begin(), order.end(),[&](int x,int y) {
                return candidate[x] > candidate[y];
            });
            ans = max(ans, min(candidate.at(order.at(3)), max_ability.at(order.at(4))));
        }
    }
    cout << ans << endl;
}
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iterator>
#include <math.h>
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define MOD 1000000007;
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // int T,p;
    // cin>>T; 
    // for(p=1;p<=T;p++)
    // {
            // ll N,M;
            
            ll N;
            cin>>N;
            ll A[N][5],a,b,c,i,j,k;

            vector <vector <pair <ll,ll> > > vect(5);

            for(i=0;i<N;i++)
            {
                cin>>A[i][0]>>A[i][1]>>A[i][2]>>A[i][3]>>A[i][4];
                vect[0].pb(mp(A[i][0],i));
                vect[1].pb(mp(A[i][1],i));
                vect[2].pb(mp(A[i][2],i));
                vect[3].pb(mp(A[i][3],i));
                vect[4].pb(mp(A[i][4],i));
            }

            sort(vect[0].begin(),vect[0].end());
            sort(vect[1].begin(),vect[1].end());
            sort(vect[2].begin(),vect[2].end());
            sort(vect[3].begin(),vect[3].end());
            sort(vect[4].begin(),vect[4].end());


            ll ans=-1e15;

            for(i=0;i<5;i++)
            {
                for(j=0;j<N;j++)
                {
                    for(k=0;k<N;k++)
                    {
                        if(j==k)
                        continue;
                        a=1e15;
                        for(b=0;b<5;b++)
                        {
                            if(b==i)
                            continue;
                            a=min(a,max(A[j][b],A[k][b]));   
                        }

                        b=N-1;
                        while((vect[i][b].second==k)||(vect[i][b].second==j))
                        {
                            b--;
                        }
                        a=min(a,vect[i][b].first);

                        ans=max(ans,a);
                    }
                }
            }

            cout<<ans;
            return 0;
}