#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

void chmin(int &ret, const int &tg) {
    if (tg < ret) ret = tg;
}
void chmax(int &ret, const int &tg) {
    if (tg > ret) ret = tg;
}

const int INF = 1e9 + 10;
const int M = 5;
const int K = 3;
int ans = 0;

void dfs(int m, vvi &R, const vvi &P) {
    if (m < M) {
        rep(k, R.size()) {
            R[k].push_back(m);
            dfs(m + 1, R, P);
            R[k].pop_back();
        }
        if (R.size() < K) {
            R.push_back({m});
            dfs(m + 1, R, P);
            R.pop_back();
        }
    } else {
        vi ret(R.size(), 0);
        rep(i, P.size()) {
            rep(j, ret.size()) {
                int r = INF;
                for (int k : R[j]) {
                    chmin(r, P[i][k]);
                }
                chmax(ret[j], r);
            }
        }
        chmax(ans, *min_element(ret.begin(), ret.end()));
    }
    return;
}
int main() {
    int N;
    cin >> N;
    vvi P(N, vi(M));
    rep(i, N) { rep(j, M) cin >> P[i][j]; }

    vvi R;
    dfs(0, R, P);
    cout << ans << endl;
    return 0;
}

//IQ134高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
#define MODB  998244353 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}



int main() {
	ll ans = 0;
	ll tmp = 0;
	int n; cin >> n;
	int a[n][5];
	REP(i, n) REP(j, 5) cin >> a[i][j];
	int he = 0, bo = 1000000001;
	int now;
	set<int> mp;
	while(he + 1 < bo){
		now = (he + bo) / 2;
		//cout << he << "," << bo << ":" << now << endl;
		mp.clear();
		REP(i, n){
			int bit = 0;
			REP(j, 5){
				bit = bit << 1;
				if(a[i][j] >= now) bit++;
			}
			mp.insert(bit);
		}
		bool ch = false;
		for(auto i = mp.begin(); i != mp.end(); i++){
			for(auto j = mp.begin(); j != mp.end(); j++){
				for(auto k = mp.begin(); k != mp.end(); k++){
					if(((*i | *j)| *k) == (1 << 5) - 1){
						//cout << bitset<5>(*i) << endl << bitset<5>(*j) << endl << bitset<5>(*k) << endl << endl;
						ch = true;
					}
				}
			}
		}
		if(ch) he = now;
		else bo = now;
	} 
	cout << he << endl;
}