#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define V vector
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define sz(x) int(x.size())
#define pcnt __builtin_popcountll
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template <typename T> void print(T a) {cout << a << ' ';}
template <typename T> void printe(T a) {cout << a << endl;}
template <typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;}
template <typename T> void printp(pair<T, T> a) {print(a.first); cout<<a.second<<endl;}
template <typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
template <typename T> using vc = vector<T>;
template <typename T> using vv = vc<vc<T>>;
template <typename T> using vvv = vc<vv<T>>;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vvl = vv<ll>;
vi di = {-1, 1,  0, 0, -1, -1,  1, 1};
vi dj = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    int n; cin >> n;
    int m = 5;
    vvi a(n, vi(m)); rep(i, n) rep(j, m) cin >> a[i][j];
    vi MX(m, 0);
    rep(i, n) rep(j, m) chmax(MX[j], a[i][j]);
    int ans = 0;
    rep(i, n) {
        rep(j, i) {
            vi mx(m); // i,jさんの最大値
            rep(k, 5) mx[k] = max(a[i][k], a[j][k]);
            int mn = 2e9, im = -1;
            rep(k, 5) if (chmin(mn, mx[k])) im = k;
            mx[im] = MX[im];
            int res = 2e9;
            rep(k, 5) chmin(res, mx[k]);
            chmax(ans, res);
        }
    }
    cout << ans << endl;
    return 0;
}
#include <bits/stdc++.h>
#define speedup                                                       \
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr), \
		cout.precision(16)
using namespace std;
using ll = long long;
#define pb push_back
#define all(x) (x).begin(), (x).end()
using ld = long double;

void solve() {
	int n;
	cin>>n;
	vector<vector<ll>> ar(n,vector<ll>(5));
	for(auto& it:ar) {
		for(auto& iit:it) {
			cin>>iit;
		}
	}
	ll l=0,r=1e10;
	while(l<r) {
		ll md=(l+r)>>1;
		vector<int> cnt(32);
		for(auto& it:ar) {
			int msk=0;
			for(int i=0;i<5;++i) {
				if(it[i]>=md) {
					msk|=1<<i;
				}
			}
			++cnt[msk];
		}
		int ok=false;
		for(int i=0;i<32;++i) {
			for(int j=0;j<32;++j) {
				for(int k=0;k<32;++k) {
					int tmp=0;
					if(cnt[i]>0) tmp|=i;
					if(cnt[j]>0) tmp|=j;
					if(cnt[k]>0) tmp|=k;
					if(tmp==31) {
						ok=true;
						break;
					}
				}
			}
		}
		if(ok) l=md+1;
		else r=md;
	}
	cout<<r-1<<'\n';
}

int main() {
	speedup;
	//int t;
	//cin >> t;
	//while (t--)
		solve();
}
