#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define PRECISION cout << fixed << setprecision(20);

using namespace std;

template<class Fun>
class y_combinator_result {
    Fun fun_;
public:
    template<class T>
    explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}

    template<class ...Args>
    decltype(auto) operator()(Args &&...args) {
        return fun_(std::ref(*this), std::forward<Args>(args)...);
    }
};

template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
    return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

void solve() {
    int n;
    cin >> n;
    vector<array<int, 5>> arr(n);
    vector<int> store;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 5; j++) {
            cin >> arr[i][j];
            store.push_back(arr[i][j]);
        }
    }
    
    sort(store.begin(), store.end(), greater<>());

    int low = 0, high = 1e9 + 6;

    auto check = [&](int x) -> bool {
        vector<int> mask(5, -1);
        auto get = y_combinator([&](auto get, int pos) -> bool {
            if (pos == 5) {
                vector<vector<int>> all(3);
                for (int i = 0; i < 5; i++) {
                    all[mask[i]].push_back(i);
                }
                for (int who = 0; who < 3; who++) {
                    if (all[who].size()) {
                        int done = 0;
                        for (int i = 0; i < n; i++) {
                            int ok = 1;
                            for (int j: all[who]) {
                                if (arr[i][j] < x) {
                                    ok = 0; break;
                                }
                            }
                            if (ok) {
                                done = 1;
                                break;
                            }
                        }
                        if (!done) {
                            return false;
                        }
                    }
                }
                return true;
            }

            for (int i = 0; i <= 2; i++) {
                mask[pos] = i;
                if (get(pos + 1)) {
                    return true;
                } 
            }
            return false;
        });

        return get(0);
    };

    while (low + 1 < high) {
        int mid = (low + high) / 2;
        if (check(mid)) {
            low = mid;
        } else {
            high = mid;
        }
    };

    cout << low << "\n";
}

int main() {
    FASTIO;
    PRECISION;

    int t = 1;
    // cin >> t;

    for (int i = 1; i <= t; i++) {
        solve();
    }
}
#include <bits/stdc++.h>

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

const ll mod = 1e9 + 7 ;

int main(){
    ll n ;
    cin >> n ;
    ll ans = 0 ;
    map<ll,ll> P ;
    rep(i,n){
        ll p ;
        cin >> p ;
        P[p]++ ;
        if( p == ans ){
            for(ll j = ans ; ans < 200003 ; j++ ){
                if(P[j] != 0 ) continue ;
                else{
                    cout << j << endl;
                    ans = j ;
                    break ;
                }
            }
        }
        else{
            cout << ans << endl ;
        }
    }
}