#include <bits/stdc++.h>

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int dp[3030][10][50];

void init(){
    rep(i, 3030) rep(j, 10) rep(k, 50) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    vector<int> A(N), B(N), C(N), D(N), E(N);
    rep(i, N) cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i];
    int ok = 0, ng = INF;
    int m = (ok+ng)/2;
    while(abs(ok-ng) > 1){
        //cout << "m: " << m << endl;
        init();
        rep(i, N){
            int val = 0;
            if(A[i] >= m) val += (1 << 4);
            if(B[i] >= m) val += (1 << 3);
            if(C[i] >= m) val += (1 << 2);
            if(D[i] >= m) val += (1 << 1);
            if(E[i] >= m) val += (1 << 0);
            //cout << i << ": " << val << endl;
            for(int ninzuu = 0; ninzuu < 5; ninzuu++){
                rep(now_state, (1 << 5)){
                    dp[i+1][ninzuu][now_state] = max(dp[i+1][ninzuu][now_state], dp[i][ninzuu][now_state]);
                    dp[i+1][ninzuu+1][now_state|val] = max(dp[i+1][ninzuu+1][now_state|val], dp[i][ninzuu][now_state]);
                }
            }
        }
        if(dp[N][3][(1 << 5)-1] == 1) ok = m;
        else ng = m;
        m = (ok+ng)/2;
    }
    cout << ok << endl;
    return 0;
}
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int MOD2 = 998'244'353;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








bool okay(int x, std::vector<std::vector<int>> &M){
    std::set<int> s;
    for(auto &e: M){
        int bit{};
        for(auto m: e){
            bit *= 2;
            bit |= (m >= x);
        }

        s.insert(bit);
    }
    for(int a: s) for(int b: s) for(int c: s){
        if((a | b | c) == 31) return true;
    }
    return false;
}

int main(){
    int N; std::cin >> N;
    std::vector<std::vector<int>> mem(N, std::vector<int>(5));
    for(auto &e: mem){
        for(auto &m: e) std::cin >> m;
    }
    int ok{}, ng{INF + 1};
    while(ng > ok + 1){
        int mid{(ok + ng) / 2};
        if(okay(mid, mem)) ok = mid;
        else               ng = mid;
    }
    std::cout << ok << std::endl;
    return 0;
}
