#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll  long long
#define pb push_back
#define vec vector<ll>
#define pii pair<ll,ll>
#define pr_que priority_queue<pii,vector<pii>,greater<pii> >
#define itr(i,x,y) for(ll i=x;i<y;i++)
#define mod 1000000007
const long long N=200001,INF=1000000000000000000;
const double err=1e-9;

int main()
{
	IOS;
	int n;
	cin >> n;
	int a[n][5];
	itr(i,0,n)
	{
		itr(j,0,5)
		{
			cin >> a[i][j];
		}
	}
	int lo=1,hi=1e9,mid;
	while(lo<hi)
	{
		mid=lo+(hi-lo+1)/2;
		bool v[1<<5];
		itr(i,0,1<<5) v[i]=false;
		itr(i,0,n)
		{
			int mask=0;
			itr(j,0,5)
			{
				if(a[i][j]>=mid)
				{
					mask=mask^(1<<j);
				}
			}
			v[mask]=true;
		}
		bool c=false;
		itr(i,0,1<<5)
		{
			if(!v[i]) continue;
			itr(j,0,1<<5)
			{
				if(!v[j]) continue;
				itr(k,0,1<<5)
				{
					if(!v[k]) continue;
					
					if((i|j|k) == (1<<5)-1)
					{
						c=true;
					}	
				}
			}
		}
		if(c==true) lo=mid;
		else hi=mid-1;
	}
	cout << lo << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll A[3020][5];
ll N;

bool isOK(ll key){
  vector<ll> aup(32);
  rep(i,N){
    ll temp = 0;
    rep(k,5){
      if(A[i][k]>=key){
        temp+=pow(2,k);
      }
    }
    aup[temp]++;
  }
  bool aru = 0;
  rep(i,32){
    rep(k,32){
      rep(t,32){
        if((i|k|t) == 31){
          if(aup[i]>0&&aup[k]>0&&aup[t]>0){
            //cout << i << k << t << endl;
            aru = 1;
          }
        }
      }
    }
  }
  return aru;
}
            
        
    


int main(){
  cin>>N;
  rep(i,N){
    cin>>A[i][0]>>A[i][1]>>A[i][2]>>A[i][3]>>A[i][4];
  }
  ll right = MOD;
  ll left = -1;
  while((right-left)>1){
    ll mid=left+(right-left)/2;
    if(isOK(mid)){
      left = mid;
    }
    else{
      right = mid;
    }
  }
  cout << left << endl;
  return 0;
}