#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll=long long;
using ld=long double;
using pll=pair<ll, ll>;
//using mint = modint1000000007;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo 2e18
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
//priority_queue<ll, vector<ll>, greater<ll>> Q;
/*
3000*3000*5*3
2人とったら、おのずと1人きまる
1000*1000*100まで
2人とった場合は出せる。
2ブタン？10以上をもつとか
でbool
*/
ll A[3010][5];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  
  ll N;
  cin >> N;
  rep(i, N) rep(j, 5) cin >> A[i][j];
  ll high=1e9;
  ll low=1;
  ll mid=(high+low)/2;
  while(high > low+1){
    set<ll> S;
    rep(i, N){
      ll tmp=0;
      rep(j, 5){
        if (A[i][j]>=mid){
          tmp+=1<<j;
        }
      }
      if (tmp) S.insert(tmp);
    }
    vector<ll> Q;
    for(auto s: S)
      Q.push_back(s);
    bool fin=false;
    ll tsz=Q.size();
    if(tsz>3){
      rep(i, tsz){
        for(ll j=i+1; j<tsz; j++){
          for(ll k=j+1; k<tsz; k++){
            ll t=Q[i]|Q[j]|Q[k];
            if (t == ((1<<5)-1)){
              fin = true;
              low = mid;
            }
            if(fin) break;
          }
          if(fin) break;
        }
        if(fin) break;
      }
    }
    else{
      ll t=0;
      for(auto q: Q){
        t|=q;
      }
      if (t == ((1<<5)-1)){
        fin = true;
        low = mid;
      }
    }
    if(!fin) high=mid;
    mid = (high+low)/2;
  }

	bool fin=false;
    set<ll> S;
    rep(i, N){
      ll tmp=0;
      rep(j, 5){
        if (A[i][j]>=high){
          tmp+=1<<j;
        }
      }
      if (tmp) S.insert(tmp);
    }
    vector<ll> Q;
    for(auto s: S)
      Q.push_back(s);
    ll tsz=Q.size();
    if(tsz>3){
      rep(i, tsz){
        for(ll j=i+1; j<tsz; j++){
          for(ll k=j+1; k<tsz; k++){
            ll t=Q[i]|Q[j]|Q[k];
            if (t == ((1<<5)-1)){
              fin = true;
            }
            if(fin) break;
          }
          if(fin) break;
        }
        if(fin) break;
      }
    }
    else{
      ll t=0;
      for(auto q: Q){
        t|=q;
      }
      if (t == ((1<<5)-1)) fin=true;
    }
    if(!fin) high--;
    cout << high << endl;
}

/*
5
3 2 2 2 2
2 3 2 2 2
2 2 3 2 2
2 2 2 3 2
2 2 2 2 3
*/
#include <bits/stdc++.h>
using namespace std;

const int N = 3000 + 9;

int a[N][5], b[N];

int cnt[1 << 5];

vector<int> vc[N];

bool check(int x, int n) {
    memset(cnt, 0, sizeof(cnt));
    for (int i = 1; i <= n; ++i) {
        b[i] = 0;
        for (int j = 0; j < 5; ++j) {
            if (a[i][j] >= x) {
                b[i] |= 1 << j;
            }
        }
        ++cnt[b[i]];
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            --cnt[b[i]];
            --cnt[b[j]];
            int x = ~(b[i] | b[j]) & 31;
            if (!x) return true;
            for (int y : vc[x]) if (cnt[y]) return true;
            ++cnt[b[i]];
            ++cnt[b[j]];
        }
    }
    return false;
}

int main() {
    for (int i = 0; i < (1 << 5); ++i) {
        for (int j = 0; j < (1 << 5); ++j) {
            if ((i & j) == i) vc[i].push_back(j);
        }
    }
    int n; scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < 5; ++j) {
            scanf("%d", &a[i][j]);
        }
    }
    int L = 1, R = 1000000000;
    while (L < R) {
        int M = ((L + R) >> 1) + 1;
        if (check(M, n)) L = M;
        else R = M - 1;
    }
    printf("%d\n", L);
    return 0;
}