#include <bits/stdc++.h>

using namespace std;

#define ull unsigned long long
#define ll long long
#define ui unsigned int
#define us unsigned short
#define inf_int 1e9
#define inf_ll 1e18
#define mod 1000000007
#define smod 998244353

vector<pair<ll, ll>> v[5];

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	
	int n;
	cin >> n;
	
	vector<pair<ll, ll>> v[5];
	ll data[n][5];
	for(int x=0;x<n;x++){
		for(int y=0;y<5;y++){
			cin >> data[x][y];
			v[y].push_back({data[x][y], x});
		}
	}
	
	for(int x=0;x<5;x++){
		sort(v[x].begin(), v[x].end());
	}
	ll ans = 0;
	for(int x=0;x<n;x++){
		for(int y=x+1;y<n;y++){
			vector<pair<ll, ll>> tmp;
			for(int z=0;z<5;z++){
				tmp.push_back({max(data[x][z], data[y][z]), z});
			}
			
			sort(tmp.begin(), tmp.end());
						
			for(int i=1;i<=3;i++){
				int idx = v[tmp[0].second][n-i].second;
				if(idx == x || idx == y) continue;
				
				tmp[0].first = max(tmp[0].first, v[tmp[0].second][n-i].first);
				break;
			}
			
			ll mn = inf_ll;
			for(int z=0;z<5;z++) mn = min(mn, tmp[z].first);
			ans = max(ans, mn);
		}
	}
	cout << ans << "\n";
    return 0;
}

// Santai
// Pikirin dengan benar-benar
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vector<int>>;
using viii = vector<vector<vector<int>>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define len(a) (int)a.size()
#define all(a) a.begin(), a.end()

const int INF32 = 1 << 30;
const long long INF64 = 1LL << 60;
const double PI = acos(-1);

bool check(int x, vii A) {
    // N人ごとにA-Eが判定値xを満たしているかを5bitで算出
    set<int> s;
    for (auto a: A) {
        int bits = 0;
        for (auto v: a) {
            bits <<= 1;
            if (v >= x) bits |= 1;
        }
        s.insert(bits);
    }
    // 3人選んで、ABCDEいずれも基準を満たすかどうかを確認
    for (auto s1: s) {
        for (auto s2: s) {
            for (auto s3: s) {
                if ((s1 | s2 | s3) == 0b11111) {
                    return true;
                }
            }
        }
    }
    return false;
}

int main() {
    int N;
    cin >> N;
    vii A(N, vi(5));
    rep(i, N) rep(j, 5) cin >> A[i][j];

    int left = 0;
    int right = INF32;
    while (right - left > 1) {
        int mid = (left + right) / 2;
        (check(mid, A) ? left : right) = mid;
    }
    cout << left << endl;
}
