#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define io ios::sync_with_stdio(false); cin.tie(0)

int a[3003][5];

int main()
{
    io;
    int n; cin >> n;
    rep(i, n) rep(j, 5) cin >> a[i][j];
    int ok = 0, ng = 1e9+1;
    auto check = [&](int x) {
        set<int> s;
        rep(i, n) {
            int bit = 0;
            rep(j, 5) {
                bit <<= 1;
                bit |= (a[i][j] >= x);
            }
            s.insert(bit);
        }
        for (int x : s) for (int y : s) for (int z : s) {
            if ((x | y | z) == 31) return true;
        }
        return false;
    };
    while (abs(ok-ng) > 1) {
        int mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define N 10005
bitset<N>p[5],f[3];
int n,i,l,r,cnt,mid,a[N][10],c[10],fl,b[5][5],e[10];
bool check(){
	int i;
	for(i=1;i<=n;++i)f[0][i]=f[1][i]=f[2][i]=1;
	for(i=0;i<5;++i){
		f[e[i]]&=p[i];
	}
	if(f[0].count()&&f[1].count()&&f[2].count())return 1;
	return 0;
}
void dfs(int now){
	if(now==5){fl|=check();return ;}
	e[now]=0;dfs(now+1);e[now]=1;dfs(now+1);e[now]=2;dfs(now+1);
}
int check(int x){
	for(int i=0;i<5;++i){
		for(int j=1;j<=n;++j){
			if(a[j][i]>=x)p[i][j]=1;else p[i][j]=0;
		}
	}
	fl=0;dfs(1);if(fl)return 1;return 0;
}
int main(){
	cin>>n;
	for(i=1;i<=n;++i)cin>>a[i][0]>>a[i][1]>>a[i][2]>>a[i][3]>>a[i][4];
	l=0;r=1e9;
	while(l<r){
		mid=r-(r-l>>1);
		if(check(mid))l=mid;
		else r=mid-1;
	} cout<<l;
}