#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  int n;cin>>n;
  int a[n],b[n],c[n],d[n],e[n];
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i]>>d[i]>>e[i];
  }
  int minn=0;int maxx=1e9;int ans=0;
  while(minn<=maxx){
    int midd=minn+(maxx-minn)/2;
    /*int cnt[32];
    for(int i=0;i<32;i++){
      cnt[i]=0;
    }*/
    set<int>cnt;
	for(int i=0;i<n;i++){
      int val=0;
      if(a[i]>=midd)val=(val|(1<<4));
      if(b[i]>=midd)val=(val|(1<<3));
      if(c[i]>=midd)val=(val|(1<<2));
      if(d[i]>=midd)val=(val|(1<<1));
      if(e[i]>=midd)val=(val|(1<<0));
      cnt.insert(val);
    }
    int f=0;
    /*for(int i=0;i<32;i++){
      if(cnt[i]==0)continue;
      if(i==31 && cnt[i]>=3){
        f=1;break;
      }
      for(int j=i+1;j<32;j++){
        if(cnt[j]==0)continue;
        int val=(i|j);
        if(cnt[i]+cnt[j]>=3 && val==31){
          f=1;break;
        }
        for(int k=j+1;k<32;k++){
          if(cnt[k]==0)continue;
          val=(val|k);
          if(val==31){
            f=1;break;
          }
        }
        if(f==1)break;
      }
      if(f==1)break;
    }*/
    for(int x:cnt){
      for(int y:cnt){
        for(int z:cnt){
          if((x|y|z)==31){
            f=1;break;
          }
        }
        if(f==1)break;
      }
      if(f==1)break;
    }
    if(f==1){
      ans=max(ans,midd);
      minn=midd+1;
    }
    else maxx=midd-1;
  }
  cout<<ans<<endl;
}
#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
map<ll, bool> mp; //防止重复计算
int main()
{
    ll n, s = 0;
    cin >> n;
    ll k = sqrt(n);
    for (ll a = 2; a <= k; a++) //底数从2枚举到√n
    {
        ll b = 2; //指数从2开始枚举
        while (1)
        {
            ll c = pow(a, b);
            if (c > n) //当a^b大于n时，结束循环
                break;
            if (!mp[c]) //如果还没有出现过
            {
                mp[c] = 1; //记录下这个可展开数
                s++;
            }
            b++;
        }
    }
    printf("%lld\n", n - s);
    return 0;
}