#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
  return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
  return ((T(1) << idx) & b) != 0;
}

int main(int argc, char *argv[]) {
  i64 i, j, k;
  i64 N; cin >> N;
  vector<array<i64, 5>> A(N);
  REP(0, N, i) {
    REP(0, 5, j) {
      RI(A[i][j]);
    }
  }

  auto check = [&](i64 val) {
    using ull = unsigned long long;
    vector<ull> B(N, 0);
    //cerr << val << endl;
    REP(0, N, i) {
      REP(0, 5, j) {
        if(A[i][j] >= val) {
          B[i] |= 1LL << j;
        }
      }
      //cerr << B[i] << " ";
    }
    //cerr << endl;

    vi FS(32, 0);
    REP(0, N, i) {
      REP(i+1, N, j) {
        //cerr << i << " " << j << endl;
        ull res = (~(B[i] | B[j])) & 31;
        if(FS[res] == 1) {
          //cerr << "found\n";
          return true;
        }
        //cerr << "not found\n";
      }
      REP(0, 32, k) {
        if((ull(k) & B[i]) == ull(k)) {
          //cerr << "add FS " << k << endl;
          FS[k] = 1;
        }
      }
    }
    return false;
  };

  i64 L = 0, H = 1000000000LL+1;
  assert(check(L));
  assert(!check(H));
  while(H - L > 1) {
    i64 M = (H + L) / 2;
    if(check(M)) {
      L = M;
    }
    else {
      H = M;
    }
  }
  WI(L);

  return 0;
}


/*
**    author : Dhiraj Govindvira
**      date : 02 May 2021 ~ Sunday
**      time : 09:20:20 PM
*/

#include <bits/stdc++.h>
using namespace std;

#ifdef DHIRAJ
    #include "D:/dhiraj/Programming/debug.h"
#else
    #define dbg(...) 1
    #define cerr if(0) cerr
#endif

using ll = long long int;
#define endl '\n'

template <typename T, typename U>
inline istream & operator >> (istream &in, pair<T, U> &p) {
    in >> p.first >> p.second;
    return in;
}
template <typename T>
inline istream & operator >> (istream &in, vector<T> &v) {
    for(T &x : v) in >> x;
    return in;
}

void solve(ll &tc)
{
    ll n;
    cin >> n;

    vector<vector<ll>> a(n, vector<ll>(5));
    for(ll i = 0; i < n; i++) {
        for(ll j = 0; j < 5; j++) {
            cin >> a[i][j];
        }
    }

    auto f = [&](ll m)
    {
        vector<ll> b(32, 0);
        for(ll i = 0; i < n; i++) {
            ll x = 0;
            for(ll j = 0; j < 5; j++) {
                if(a[i][j] >= m) {
                    x |= (1ll << j);
                }
            }
            b[x] = 1;
        }
        for(ll i = 0; i < 32; i++) {
            for(ll j = 0; j < 32; j++) {
                for(ll k = 0; k < 32; k++) {
                    if(b[i] and b[j] and b[k]) {
                        if((i | j | k) == 31) {
                            return 1;
                        }
                    }
                }
            }
        }
        return 0;
    };

    ll l = 1, r = 1e9 + 5;
    while(l <= r)
    {
        ll m = (l + r) / 2;
        if(f(m)) {
            l = m + 1;
        }
        else {
            r = m - 1;
        }
    }
    cout << l - 1 << endl;
}

int main()
{
    #ifdef DHIRAJ
        freopen("D:/dhiraj/Programming/i1.txt", "r", stdin);
        freopen("D:/dhiraj/Programming/o1.txt", "w", stdout);
        freopen("D:/dhiraj/Programming/e1.txt", "w", stderr);
    #endif

    ios::sync_with_stdio(0);
    cin.tie(0);

    ll rep = 3;
    while(rep--) {
        ll tc = 1;
        for(ll i = 1; i <= tc; i++) {
            cerr << "Case #" << i << "\n";
            solve(i);
        }
        if(dbg()) break;
    }
    return 0;
}