#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int a[5][3030];
int a1[5][5] = {};
int i1[5];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[0][i] >> a[1][i] >> a[2][i] >> a[3][i] >> a[4][i];
		for (int j = 0; j < 5; j++) {
			if (a1[j][j] < a[j][i]) {
				for (int k = 0; k < 5; k++) {
					a1[k][j] = a[k][i];
				}
				i1[j] = i;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < 5; k++) {
				if (i1[k] == i || i1[k] == j)continue;
				int na = max({ a[0][i],a[0][j],a1[0][k] });
				for (int l = 1; l < 5; l++) {
					int nb= max({ a[l][i],a[l][j],a1[l][k] });
					na = min(na, nb);
				}
				ans = max(ans, na);
			}
		}
	}
	cout << ans << endl;
}
#include <bits/stdc++.h>

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<ll,ll>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

const int  INF = (1 << 30) - 1;
const ll INFL = 1LL << 60;
//const ll mod = 1e9 + 7;
const ll mod = 998244353;




int main() {

	int n;
	cin >> n;
	int ok = INF;
	int ng = 0;
	VVI a(n,VI(5));
	REP(i, n)REP(j, 5)cin >> a[i][j];

	while (ok - ng > 1) {
		bool ok3 = false;
		int mid = (ok + ng) / 2;
		VVB k(n, VB(5, false));
		bool check[5];
		REP(i, 5)check[i] = false;
		REP(i, n) {
			REP(j, 5) {
				if (a[i][j] >= mid) {
					k[i][j] = true;
					check[j] = true;
				}
			}
		}
		REP(i, n) {
			if (ok3)break;
			REP(j, i) {
				bool ok2[5];
				int cnt = 0;
				REP(l, 5)ok2[l] = false;
				REP(l, 5) {
					if (k[i][l] || k[j][l]) {
						ok2[l] = true;
						cnt++;
					}
				}
				if (cnt == 5) {
					ok3 = true;
					break;
				}
				else if (cnt == 4) {
					REP(l, 5) {
						if (!ok2[l] && check[l]) {
							ok3 = true;
							break;
						}
					}
				}
			}
		}
		if (ok3) {
			ng = mid;
		}
		else {
			ok = mid;
		}
	}
	cout << ng << endl;
}