#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 3e3; int n;
lli a[maxN][5];
map<vector<int>, int> cnt;

vector<int> merge(vector<int> &a1, vector<int> a2)
{
  vector<int> ans(5);
  for (int i = 0; i < 5; i++) ans[i] = max(a1[i], a2[i]);
  return ans;
}
bool bruteForce(map<vector<int>, int>::iterator it = cnt.begin(), int chosen = 0, vector<int> curr = {0, 0, 0, 0, 0})
{
  if (chosen == 3 && *min_element(curr.begin(), curr.end()) == 1)
    return true;
  if (it == cnt.end())
    return false;

  if (bruteForce(next(it), chosen, curr))
    return true;
  for (int j = 1; chosen + j <= 3 && j <= it->second; j++)
  {
    curr = merge(curr, it->first);
    if (bruteForce(next(it), chosen + j, curr))
      return true;
  }
  return false;
}

bool can(lli x)
{
  cnt.clear();
  for (int i = 0; i < n; i++)
  {
    vector<int> b(5);
    for (int j = 0; j < 5; j++)
      b[j] = a[i][j] >= x;
    if (!cnt.count(b)) cnt[b] = 0;
    cnt[b]++;
  }

  return bruteForce();
}

int main()
{
  while (~scanf("%d", &n))
  {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 5; j++)
        scanf("%lld", &a[i][j]);

    lli lo = 0, hi = 1e9;
    while (lo < hi)
    {
      lli mid = (lo + hi + 1) >> 1LL;
      if (can(mid)) lo = mid;
      else hi = mid - 1;
    }

    printf("%lld\n", lo);
  }
  return 0;
}
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

	#define sim template < class c
	#define ris return * this
	#define dor > debug & operator <<
	#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
	sim > struct rge { c b, e; };
	sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
	sim > auto dud(c* x) -> decltype(cerr << *x, 0);
	sim > char dud(...);
	struct debug {
			// #ifdef LOCAL
		~debug() { cerr << endl; }
		eni(!=) cerr << boolalpha << i; ris; }
		eni(==) ris << range(begin(i), end(i)); }
		sim, class b dor(pair < b, c > d) {
			ris << "(" << d.first << ", " << d.second << ")";
		}
		sim dor(rge<c> d) {
			*this << "[";
			for (auto it = d.b; it != d.e; ++it)
				*this << ", " + 2 * (it == d.b) << *it;
			ris << "]";
		}

			// sim dor(const c&) { ris; }
	};
	#ifdef ASJKD
}
	#endif
	#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
	#define read(x) for(auto &i : (x)){cin>>i;}
	#define all(x) begin(x), end(x)
	#define pb push_back
#define maxn 1500
ll mod = 998244353;
int INF = 1e9+1e8+1e7;
ll INF64 = 1e18;

long long binpow(long long a, long long b, long long m) {
	a %= m;
	long long res = 1;
	while (b > 0) {
		if (b & 1){
			res = res * a % m;
		}
		a = a * a % m;
		b >>= 1;
	}
	return res;
}

struct pl{
	vector<int> h;
	void readd(){
		h.resize(5);
		for(int i=0;i<5;i++){
			cin>>h[i];
		}
	}
	bool amgood(vector<int> &sub, pl &other){
		int mn = INF;
		int mn2 = INF;
		for(int i=0;i<sub.size();i++){
			mn = min(h[sub[i]], mn);
		}
		for(int i=0;i<sub.size();i++){
			mn2 = min(other.h[sub[i]], mn2);
		}
		return mn > mn2;
	}
};
void test_case(int tnum){
	int n;
	cin>>n;
	vector<pl> a(n);
	for(int i=0;i<n;i++){
		a[i].readd();
	}
	vector<int> perm(5);
	for(int i=0;i<5;i++){
		perm[i]=i;
	}
	int ans =0;
	do{
		for(int t1=0;t1<=5;t1++){
			for(int t2=0;t2+t1<=5;t2++){
				vector<vector<int>> sub(3);
				for(int i=0;i<t1;i++){
					sub[0].pb(perm[i]);
				}
				for(int i=t1;i<t1+t2;i++){
					sub[1].pb(perm[i]);
				}
				for(int i=t1+t2;i<5;i++){
					sub[2].pb(perm[i]);
				}
				vector<pl> team;
				set<int> taken;
				for(int i=0;i<3;i++){
					int idx = -1;
					pl cur;
					cur.h.resize(5);
					for(int j=0;j<n;j++){
						if(!taken.count(j) && (idx == -1 or !cur.amgood(sub[i], a[j]))){
							idx = j;
							cur = a[j];
						}
					}
					taken.insert(idx);
					team.pb(a[idx]);
				}
				vector<int> mxs(5);
				for(pl p : team){
					for(int i=0;i<5;i++){
						mxs[i] = max(mxs[i], p.h[i]);
					}
				}
				ans = max(ans, *min_element(all(mxs)));
				
				// debug() << imie(sub) imie(taken) imie(perm) imie(t1) imie(t2); 
				assert(sub[0].size() + sub[1].size() + sub[2].size() == 5);
			}
		}
	} while(next_permutation(all(perm)));
	cout << ans << '\n';
}	
int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	int t=1;
	// cin>>t;
	for(int test=1;test<=t;test++){
		test_case(test);
	}
	return 0;
}