#include<cstdio>
#define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i)
using namespace std;
const int N=3005;
template<typename T>void read(T &x)
{
	bool neg=false;
	unsigned char c=getchar();
	for(;(c^48)>9;c=getchar())if(c=='-')neg=true;
	for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48);
	if(neg)x=-x;
}
int n,a[N],b[N],c[N],d[N],e[N],f[35];
bool check(int v)
{
	F(i,0,32)f[i]=0;
	F(i,0,n)
	{
		int t=0;
		if(a[i]>=v)t|=16;
		if(b[i]>=v)t|=8;
		if(c[i]>=v)t|=4;
		if(d[i]>=v)t|=2;
		if(e[i]>=v)t|=1;
		F(j,0,32)F(k,0,32)if(j!=k)
		{
			if(f[j]&&f[k]&&(j|k|t)==31)return true;
		}
		else if(f[j]>=2&&(j|t)==31)return true;
		++f[t];
	}
	return false;
}
int solve()
{
	int l=0,r=1000000001,mid;
	while(r-l>1)
	{
		mid=(l+r)>>1;
		if(check(mid))l=mid;
		else r=mid;
	}
	return l;
}
int main()
{
	read(n);
	F(i,0,n)read(a[i]),read(b[i]),read(c[i]),read(d[i]),read(e[i]);
	printf("%d\n",solve());
	return 0;
}

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

using namespace std;

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}
template <class Con>
string concat(const Con &c, const string &spr){
	stringstream ss;
	typename Con::const_iterator it = c.begin(), en = c.end();
	bool fst = true;
	for(; it != en; ++it){
		if(!fst){ ss << spr; }
		fst = false;
		ss << *it;
	}
	return ss.str();
}

template <class Con, class Fun>
vector<typename Con::value_type> cfilter(const Con &c, Fun f) {
	vector<typename Con::value_type> ret;
	typename Con::const_iterator it = c.begin(), en = c.end();
	for(; it != en; ++it){
		if(f(*it)){
			ret.emplace_back(*it);
		}
	}
	return ret;
}
#if __cplusplus >= 201103L
template <class Con, class Fun>
auto cmap(const Con &c, Fun f) -> vector<decltype(f(*c.begin()))> {
	vector<decltype(f(*c.begin()))> ret;
	ret.reserve(c.size());
	for(const auto &x: c){
		ret.emplace_back(f(x));
	}
	return ret;
}
#endif

#if __cplusplus >= 201402L
#define lambda(e) ([&](const auto &_){ return (e); })
#define lambda2(e) ([&](const auto &_a, const auto &_b){ return (e); })
#endif


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()
#define tget(t,i) get<i>(t)

#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n;
	cin >> n;
	vector<array<LL,5>> v(n);
	REP(i, n){
		REP(j, 5){
			cin >> v[i][j];
		}
	}
	LL ok = 0, ng = 1010101010;
	while(abs(ok - ng) > 1){
		LL md = (ok + ng) >> 1;
		bool f[32] = {};
		REP(i, n){
			int a = 0;
			REP(j, 5){
				if(v[i][j] >= md){
					a |= 1 << j;
				}
			}
			f[a] = true;
		}
		bool found = false;
		REP(i, 32)
		REP(j, 32)
		REP(k, 32)
		if(f[i] && f[j] && f[k] && (i | j | k) == 31){
			found = true;
		}
		if(found){ ok = md; }
		else{ ng = md; }
	}
	cout << ok << endl;
}



}
int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
