#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e10;

int main() {
    ll n;
    cin >> n;

    vvl v(n, vl(5));
    rep(i, n) {
        rep(j, 5) {
            cin >> v[i][j];
        }
    }

    // 判定問題「チームの総合力をx以上にできるか？」を二分探索で解く
    ll left = 0;
    ll right = INF;  /*・INFの値が大きすぎてオーバーフローしていないか？
                    ・INFの値が制約に対して小さすぎないか？         */
    while(right - left > 1) {
        ll x = (left + right) / 2;
        set<ll> st;
        rep(i, n) {
            ll y = 0;
            rep(j, 5) {
                if(v[i][j] >= x) {
                    y |= 1<<j;
                }
            }
            st.insert(y);
        }
        vl w;
        for(ll y : st) {
            w.pb(y);
        }
        bool ok = false;
        rep(i, (ll)w.size()) {
            rep(j, i+1) {
                rep(k, j+1) {
                    if((w[i] | w[j] | w[k]) == (1<<5) - 1) {
                        ok = true;
                    }
                }
            }
        }
        if(ok) {
            left = x;
        }
        else {
            right = x;
        }
    }

    out(left);
    re0;
}
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main(){
    int N;
    cin >> N;
    vector<vector<int>> A(5, vector<int>(N));
    for(int i = 0 ; i < N; i++) {
        for(int j = 0; j < 5; j++){
            int a;
            cin >> a;
            A[j][i] = a;
        }
    }
    int ub = 1000000001, lb = 1;
    while(ub - lb > 1){
        int mid = (lb + ub) / 2;
        vector<int> temp(N);
        for(int i = 0; i < 5; i++){
            for(int j = 0; j < N; j++){
                if(A[i][j] >= mid) temp[j] |= (1 << i);
            }
        }
        vector<int> ten(1 << 5, 10000000);
        ten[0] = 0;
        for(int j = 0; j < (1 << 5); j++){
            for(int k = 0; k < N; k++){
                ten[j | temp[k]] = min(ten[j | temp[k]], ten[j] + 1);
            }
        }
        if(ten[(1 << 5) - 1] <= 3) lb = mid;
        else ub = mid;
    }
    cout << lb << endl;
}