#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 60; i++) {
		if ((b / (1LL << i)) % 2LL == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

long long N;
long long A[3009], B[3009], C[3009], D[3009], E[3009];
int mask[3009];
int dp[32];

bool solve(long long border) {
	for (int i = 0; i < N; i++) {
		mask[i] = 0;
		if (A[i] >= border) mask[i] += 1;
		if (B[i] >= border) mask[i] += 2;
		if (C[i] >= border) mask[i] += 4;
		if (D[i] >= border) mask[i] += 8;
		if (E[i] >= border) mask[i] += 16;
	}
	for (int i = 0; i < 32; i++) dp[i] = (1 << 30);
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 31; j >= 0; j--) dp[j | mask[i]] = min(dp[j | mask[i]], dp[j] + 1);
	}
	if (dp[31] <= 3) return true;
	return false;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i];

	long long cl = 0LL, cr = 1200000000LL, cm, maxn = 0;
	for (int i = 0; i < 37; i++) {
		cm = (cl + cr) / 2LL;
		bool I = solve(cm);
		if (I == true) { maxn = max(maxn, cm); cl = cm; }
		else { cr = cm; }
	}
	cout << maxn << endl;
	return 0;
}
#include <iostream>
#include <vector>
#include <array>
#include <set>

using namespace std;

int main() {
    int N;
    cin >> N;

    vector<array<int, 5>> A(N);
    for (auto& a : A) for (int& i : a) cin >> i;

    int ok = 0, ng = 1001001001;

    auto check = [&](int x) -> bool {
        set<int> s;
        for(auto& a : A) {
            int bit = 0;
            for (int i : a) {
                bit <<= 1;
                bit |= (i >= x);
            }
            s.insert(bit);
        }
        for (int i : s) for (int j : s) for (int k : s) {
            if ((i|j|k)==31) return true;
        }
        return false;
    };

    while (abs(ng - ok) > 1) {
        int x = (ok + ng) / 2;
        if (check(x)) ok = x;
        else ng = x;
    }

    cout << ok;
}