#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <random>
#include <chrono>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int A[3456][5];

bool check(int tg, int N) {
    vector<int> valid(1 << 5, 0);
    for (int i = 0; i < N; i++) {
        int mask = 0;
        for (int j = 0; j < 5; j++)
            if (A[i][j] >= tg)
                mask += (1 << j);
        valid[mask] = 1;
    }
    for (int i = 0; i < (1 << 5); i++) {
        if (!valid[i]) continue;
        for (int j = 0; j < (1 << 5); j++) {
            if (!valid[j]) continue;
            for (int k = 0; k < (1 << 5); k++) {
                if (!valid[k]) continue;
                if ((i | j | k) == (1 << 5) - 1)
                    return true;
            }
        }
    }
    return false;
}

int main() {
    int N;
    scanf("%d", &N);
    vector<int> V(5, 0);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 5; j++) {
            scanf("%d", &A[i][j]);
        }
    }
    int l = 0, r = (int)1e9, ans = 0;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (check(mid, N)) {
            ans = mid;
            l = mid + 1;
        } else {
            r = mid - 1;
        }

    }
    printf("%d\n", ans);

    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
    * DON'T GET STUCK ON ONE APPROACH
by Benq;
*/

// 問題の URL を書いておく
// 

#include <bits/stdc++.h>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

using ll = long long;

struct M
{
    int p[5];
};

bool check(int N, int s, vector<M>& ms)
{
    Print(s);
    vector<int> ts(N);
    rep(i, N)
    {
        auto v = 0;
        rep(j, 5)
        {
            if(ms[i].p[j] >= s)
            {
                v |= (1 << j);
            }
        }
        ts[i] = v;
    }
    sort(ts.begin(), ts.end());
    ts.erase(unique(ts.begin(), ts.end()), ts.end());

    auto c = (int)ts.size();

    if(c < 3)
    {
        auto v = 0;
        rep(i, c)
        {
            v |= ts[i];
            return v == (1 << 5) - 1;
        }
    }

    for(int i = 0; i < c - 2; ++i)
    {
        for(int j = i + 1; j < c - 1; j++)
        {
            for(int k = j + 1; k < c; ++k)
            {
                auto v = ts[i] | ts[j] | ts[k];
                if(v == (1 << 5) - 1)
                {
                    return true;
                }
            }
        }
    }
    
    return false;
}

int main(int, const char**)
{
    int N;
    cin >> N;
    
    vector<M> ms(N);
    rep(i, N) cin >> ms[i].p[0] >> ms[i].p[1] >>  ms[i].p[2] >> ms[i].p[3] >>  ms[i].p[4];

    int hi = 1000000001;
    int lo = 1;
    while(hi - lo > 1)
    {
        auto m = (hi + lo) / 2;
        Print(m);
        if(check(N, m, ms))
        {
            lo = m;
        }
        else
        {
            hi = m;
        }
    }

    cout << lo << endl;

    return 0;
}
