#include<bits/stdc++.h>
using namespace std;
const int MAX = 3010;
bool dp[MAX][4][32];

void init(){
  for(int i=0; i<MAX; i++){
    for(int j=0; j<4; j++){
      for(int k=0; k<32; k++){
        dp[i][j][k] = false;
      }
    }
  }
  dp[0][0][0] = true;
}

int main(){
  int N;
  cin >> N;
  vector<vector<int>> vec(N,vector<int>(5));
  for(int i=0; i<N; i++){
    for(int j=0; j<5; j++){
      cin >> vec[i][j];
    }
  }
  int ok = 0;
  int ng = 1e9+10;
  while(ng - ok > 1){
    int mid = (ok+ng)/2;
    init();
    for(int i=0; i<N; i++){
      int B = 0;
      for(int j=0; j<5; j++){
        if(vec[i][j] >= mid){
          B = B | (1<<j);
        }
      }
      for(int j=0; j<4; j++){
        for(int k=0; k<32; k++){
          if(dp[i][j][k]){
            //使う
            if(j < 3){
              dp[i+1][j+1][k|B] = true;
            }
            //使わない
            dp[i+1][j][k] = true;
          }
        }
      }
    }
    if(dp[N][3][31]){
      ok = mid;
    }
    else{
      ng = mid;
    }
  }
  cout << ok << endl;
}
#include<bits/stdc++.h>
//#pragma GCC optimize "trapv"
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define fast_az_fuk      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll               int
#define lll              __int128
#define ull              unsigned ll
#define ld               long double 
#define pb               push_back 
#define pf               push_front
#define dll              deque<ll> 
#define vll              vector<ll>
#define vvll             vector<vll> 
#define pll              pair<ll,ll> 
#define vpll             vector<pll>
#define dpll             deque<pll>
#define mapll            map<ll,ll>
#define umapll           umap<ll,ll>
#define endl             "\n" 
#define all(v)           v.begin(),v.end() 
#define ms(a,x)          memset(a,x,sizeof(a))
#define random(l,r,T)    uniform_int_distribution<T>(l,r)(rng)


//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;


template<typename T> istream& operator >>(istream &in,vector<T> &v){ for(auto &x:v) in>>x; return in;}
template<typename T> ostream& operator <<(ostream &out,vector<T> &v){ for(auto &x:v) out<<x<<' '; return out;}
template<typename T1,typename T2> istream& operator >>(istream &in,pair<T1,T2> &p){ in>>p.first>>p.second; return in;}
template<typename T1,typename T2> ostream& operator <<(ostream &out,pair<T1,T2> &p){ out<<p.first<<' '<<p.second; return out;}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
template<class T>using uset=unordered_set<T,custom_hash>;

int32_t main()
{
    clock_t clk = clock();
    fast_az_fuk
    ll n; cin>>n;  vvll v(n,vll(5,0)); cin>>v;
    ll l = 1,r = 1e9; ll ans;
    while(l <= r){
        ll p = (r + l) /2;
        vll mask(n,0);
        for(ll i=0;i<n;i++){
            for(ll j=0;j<5;j++) if(v[i][j] >= p) mask[i] += (1<<j);
        }
        const ll M = (1<<5)-1;
        vvll hash(n,vll(1<<5,0)); bool flag=0;
        for(ll i=0;i<n;i++){
            for(ll j=i+1;j<n;j++){
                hash[j][mask[j]|mask[i]]=1;
            }
        }
        for(ll i=1;i<n;i++){
            for(ll j=0;j<=M;j++){
                hash[i][j] |= (hash[i-1][j]);
            }
        }
        for(ll i=2;i<n;i++){
            ll msk = (mask[i]^M); stack<ll> st; st.push(msk);
            while(!st.empty()){
                msk = st.top(); st.pop();
                if(hash[i-1][msk]) {flag=1; break;}
                for(ll k=0;k<5;k++) if(!(msk&(1<<k))) {
                    msk^=(1<<k); st.push(msk); msk^=(1<<k);
                }
            }
        }
        if(flag) {
            ans = p; l = p+1;
        }
        else r = p-1;
    }
    cout<<ans;
    // cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
    return 0;
}