#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T> ostream &operator<<(ostream &os, multiset<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]"; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) { dump_func(__VA_ARGS__) }
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int A[3000][5];
int main() {
    int N;
    cin >> N;
    rep(i,N){
        rep(j,5){
            cin >> A[i][j];
        }
    }
    auto check = [&](ll x) -> bool{
        vector<int> mask(N,0);
        int sz = bit(5);
        vector<int> mp(sz,0);
        rep(i,N){
            rep(j,5){
                if(A[i][j] >= x)mask[i] += bit(j);
            }
            mp[mask[i]]++;
        }
        // dump(x, mp);
        rep(k,sz){
            if(mp[k] == 0)continue;
            if((k) == sz-1 && mp[k] >= 3){
                return true;
            }
            rep(j,k){
                if(mp[j] == 0)continue;
                if((k|j) == sz-1 && mp[k]+mp[j] >= 3){
                    return true;
                }
                rep(i,j){
                    if(mp[i] == 0)continue;
                    if((i|j|k) == sz-1 && mp[i]+mp[j]+mp[k] >= 3){
                        // dump(i,j,k);
                        // dump((i|j|k));
                        // dump(mp[i],mp[j],mp[k]);
                        return true;
                    }
                }
            }
        }
        return false;
    };
    ll ok = 0;
    ll ng = INF+1;
    while(ng - ok > 1){
        ll mid = (ok + ng) / 2;
        if(check(mid))ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(5, 0));
    for(int i = 0; i < N; ++i) for(int j = 0; j < 5; ++j) cin >> A.at(i).at(j);

    int ok = 0, ng = 1000000001;
    while(abs(ok-ng) > 1) {
        int cen = (ok + ng) / 2;

        set<int> S;
        for(int i = 0; i < N; ++i) {
            int bit = 0;
            for(int j = 0; j < 5; ++j) {
                bit = bit << 1;
                bit |= A.at(i).at(j) >= cen;
            }
            S.insert(bit);
        }
        bool flg = false;
        for(auto x : S) {
            for(auto y : S) {
                for(auto z : S) {
                    if((x | y | z) == 31) {
                        flg = true;
                    }
                }
            }
        }
        if(flg) ok = cen;
        else ng = cen;
    }

    cout << ok << endl;
} 