#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <queue>

using namespace std;

int n, a[3009][5];

int vis[4][1 << 5];
int fu(int x) {
    memset(vis, 0, sizeof(vis));
    vis[0][0] = 1;
    for(int i = 0; i < n; i ++) {
        for(int j = 0; j < 3; j ++) {
            for(int k = 0; k < 1 << 5; k ++) {
                if(vis[j][k] == 0) continue;
                int v = k;
                v |= (a[i][0] >= x) << 0;
                v |= (a[i][1] >= x) << 1;
                v |= (a[i][2] >= x) << 2;
                v |= (a[i][3] >= x) << 3;
                v |= (a[i][4] >= x) << 4;
                vis[j + 1][v] = 1;
            }
        }
    }
    return vis[3][(1 << 5) - 1];
}
int main() {
    cin >> n;
    for(int i = 0; i < n; i ++)
        for(int j = 0; j < 5; j ++)
            cin >> a[i][j];
    int l = 0, r = 1e9;
    while(l < r) {
        int mid = l + r + 1 >> 1;
        if(fu(mid)) l = mid;
        else r = mid - 1;
    }
    cout << l;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

bool join(int p, vector<vector<int>> a){
    int n = a.size();
    vector<uint> vec(32);
    for(vector<int> ai : a){
        uint bit = 0;
        for(int j = 0; j < 5; j++){
            if(ai[j] >= p) bit += (1<<j);
        }
        vec[bit] = bit;
    }
    //for(uint i : vec) cout << i << ","; cout << endl;
    for(uint i : vec){
        for(uint j : vec){
            for(uint k : vec){
                if((i|j|k) == 31) return true;
            }
        }
    }
    return false;
}

int main(){
    int n; cin >> n;
    vector<vector<int>> a(n,vector<int>(5));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 5; j++){
            cin >> a[i][j];
        }
    }
    vector<int> aa(5*n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 5; j++){
            aa[5*i+j] = a[i][j];
        }
    }
    sort(aa.begin(),aa.end());
    reverse(aa.begin(),aa.end());

    for(int i : aa){
        //cout << "___" << i << endl;
        if(join(i,a)){
            cout << i << endl;
            break;
        }
    }
}