#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <tuple>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <bitset>
#include <list>
#include<iomanip>

using namespace std;
using ll = long long;
using ULL = unsigned long long;
using pll = std::pair<ll, ll>;
using vi = std::vector<int>;
using vl = std::vector<ll>;
using vb = std::vector<bool>;
using vpll = std::vector<pll>;
using db = double;
using vdb = std::vector<db>;
using qlg= std::priority_queue<ll, vl, std::greater<ll> > ; //ascending
using qll= std::priority_queue<ll, vl, std::less<ll> > ; // descending
using qdg= std::priority_queue<db, vdb, std::greater<db> > ; //ascending
using qdl= std::priority_queue<db, vdb, std::less<db> > ; // descending
template<class T>
using vv = std::vector<std::vector<T> >;


#define REPL(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FORL(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FORL(i, 0, n)

#define MREP(i, n) for (ll i= (ll)(n)-1; i>=0; i-- )
#define MFOR(i, a, b) for (ll i = (ll)(b)-1; i >= (ll)(a); i--)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
#define INF pow(10, 10)
void chmin(ll& a, ll b){ if(a > b) a = b; }
void chmax(ll& a, ll b){ if(a < b) a = b; }

vpll calc_4thval(ll p1, ll p2, vv<ll> &Statuses)
{

    vpll Larges(5);
    REP(i, 5)
    {
        Larges[i] = {max(Statuses[p1][i], Statuses[p2][i]), i};
    }
    sort( all(Larges) );
    return Larges;
}


int main(void)
{

    ll  N;

    cin >> N;
    vv<ll> Statuses(N, vl(5));
    vl Maxvals(5, 0);
    REP(i, N)
    {
        REP(k, 5)
        {
            cin >> Statuses[i][k];
            Maxvals[k] = max(Maxvals[k], Statuses[i][k]);
        }

    }




    /*
    2人で4つ
    */
    ll ans = 0;
    REP(p1, N)
    {
        REP(p2, N)
        {
            if(p1 == p2) continue;
            vpll Stats_2p = calc_4thval(p1, p2, Statuses);
            bool flag = false;
            ll Min = Stats_2p[0].first;
            ll candidate = Stats_2p[1].first;


            REP(i, 5)
            {
                ll subject = Stats_2p[i].second;
                if(Min == Stats_2p[i].first && Maxvals[subject] >= ans)
                {
                    ans = max(ans, min(candidate, Maxvals[subject]) );
                }
            }


        }
    }



    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//const ll INF = numeric_limits<ll>::max() / 4;
//const int INF = numeric_limits<int>::max() / 4;

int main() {
	int N;
	cin >> N;
	vector<vector<int> > X(5, vector<int>(N,0));
	int mx = 0;
	for(int i = 0; i < N; i++){
		for(int k = 0; k < 5; k++){
			cin >> X[k][i];
			mx = (mx < X[k][i] ? X[k][i] : mx);

		}

	}
	int bl = 0;
	int bu = mx + 1;
	vector<bool> P(32);
	while(bl + 1 < bu){
		int b = (bl + bu) / 2;
		fill(P.begin(),P.end(),false);
		for(int i = 0; i < N; i++){
			int t = 0;
			for(int k = 0; k < 5; k++){
				if(b <= X[k][i]) t |= (1 << k);
			}
			P[t] = true;
		}
		bool f = false;
		for(int i1 = 1; i1 < 32; i1++){
			if(!P[i1]) continue;
			for(int i2 = i1; i2 < 32; i2++){
				if(!P[i2]) continue;
				for(int i3 = i2; i3 < 32; i3++){
					if(!P[i3]) continue;
					if(((i1 | i2) | i3) == 31){
						f = true;
						break;
					}
				}
				if(f) break;
			}
			if(f) break;
		}
		if(f){
			bl = b;
		}else{
			bu = b;
		}
	}
	cout << bl << endl;
	return(0);
}
