//https://atcoder.jp/contests/zone2021/tasks/zone2021_c
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool chk(vector<vector<int>> &arr, int mid)
{
    int n=arr.size();
    set<int> st;
    for (int i = 0; i < n; i++)
    {
        int c=0;
        for (int j = 0; j < 5; j++)
        {
            int bit=0;
            if(arr[i][j]>=mid) bit=1;
            c+=(bit<<j);
        }
        st.insert(c);
    }
    for(auto e:st)
        for(auto f:st)
            for(auto g:st)
            {
                if((e|f|g)==31)
                    return 1;
            }
    return 0;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<vector<int>> arr(n, vector<int>(5, 0));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 5; j++)
            cin >> arr[i][j];
    }

    int l = 1, r = 1e9 + 1;
    while (l < r)
    {
        int mid = (l + r)/2;
        if(chk(arr,mid))    l=mid+1;
        else r=mid;
    }
    cout<<l-1<<endl;
}

#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    array<vector<int>, 5> A;
    rep(i, 5) A[i].resize(N);
    rep(i, N) cin >> A[0][i] >> A[1][i] >> A[2][i] >> A[3][i] >> A[4][i];

    int low = 1, high = 1e9 + 1;
    vector<int> B(N);
    array<int, 1 << 5> cnt;
    while (high - low > 1) {
        int mid = (low + high) / 2;
        B.assign(N, 0);
        rep(k, 5) rep(i, N) {
            B[i] |= (A[k][i] >= mid) << k;
        }
        fill(all(cnt), 0);
        rep(i, N) {
            cnt[B[i]]++;
        }
        bool ok = false;
        rep(a, 1 << 5) {
            if (cnt[a] == 0) continue;
            rep(b, 1 << 5) {
                if (cnt[b] == 0) continue;
                rep(c, 1 << 5) {
                    if (cnt[c] == 0) continue;
                    int bit = a | b | c;
                    if (bit == (1 << 5) - 1) ok = true;
                }
            }
        }
        if (ok) low = mid;
        else high = mid;
    }
    write(low);
}