#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repx(i, x, n) for (ll i = (ll)(x); i < (ll)(n); i++)
#define repr(i, n) for (ll i = ((ll)(n)-1); i >= 0; i--)
#define reprx(i, x, n) for (ll i = ((ll)(n)-1); i >= (ll)(x); i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((ll)(x).size())
#define submit(x) {cout<<x<<endl; return 0;}
#define X first
#define Y second
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T>bool chmax(T &a,T b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a,T b) {if (b<a) {a=b; return 1;} return 0;}
template<class T>long long ip(T a, T b) {bitset<60> s(b); long long val=1; for(int i=0;i<60;i++){if(s.test(i))val*=a; a*=a;} return val;}
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 60;
const double PI = 3.1415926535897932;

ll n;
VV<ll> par;

bool solve(ll mid) {
  set<ll> s;
  rep(i,n) {
    ll tmp = 0;
    rep(j,5) {
      if (par[i][j] >= mid) tmp += (1<<j);
    }
    s.insert(tmp);
  }
  for (auto x : s)  for (auto y : s)  for (auto z : s) {
    if ((x | y | z) == 31) return true;
  }
  return false;
}

int main() {
  cin>>n;
  par.assign(n,V<ll>(5));
  rep(i,n) rep(j,5) cin>>par[i][j];
  ll right = 1000000001;
  ll left = 0;
  ll mid = (right + left) / 2;
  while (right - left > 1) {
    if (solve(mid)) left = mid;
    else right = mid;
    mid = (right + left) / 2;
  }
  submit(left)
}

#include <bits/stdc++.h>
        #include <math.h>
    
        using namespace std;
        typedef long long ll;
        typedef unsigned long long ull;
        # define M_PI  3.14159265358979323846
    
    
        const int M=1e9+7;
        long long mod(long long x){
            return ((x%M + M)%M);
        }
        long long add(long long a, long long b){
            return mod(mod(a)+mod(b));
        }
        long long mul(long long a, long long b){
            return mod(mod(a)*mod(b));
        }
    
        ll modPow(ll a, ll b){
            if(b==0)
                return 1LL;
            if(b==1)
                return a%M;
            ll res=1;
            while(b){
                if(b%2==1)
                    res=mul(res,a);
                a=mul(a,a);
                b=b/2;
            }
            return res;
        }

        void solve (){
            ll n;
            cin>>n;
            n=2*n;
            ll ans=0;
            for(ll i=1;i*i<=n;i++){
                if(n%i==0){
                    ll f1=i;
                    ll f2=n/i;
                    if((f2+1-f1)%2==0) ans++;
                    if(n/i != i){
                    ll f1=n/i;
                    ll f2=i;
                    if((f2+1-f1)%2==0) ans++;
                    }
                }
            }
            cout<<ans;
        }
        int main(){
            ios::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            cout<<fixed;
            cout<<setprecision(10);
    //        freopen("timber_input.txt", "r", stdin);
    //        freopen("timber_output.txt", "w", stdout);
            int t=1;
            // cin>>t;
            for(int i=1;i<=t;i++){
            //    cout<<"Case #"<<i<<": ";
                solve();
            }
            return 0;
        }