#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>
#include <stack>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}

	return d;
}

int members[3000][5] = {};
int sorted[5][3000] = {};

int main(void) {

	int N;
	cin >> N;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 5; j++) {
			cin >> members[i][j];
			sorted[j][i] = members[i][j];
		}
	}

	for (int j = 0; j < 5; j++) {
		sort(sorted[j],sorted[j] + N);
	}

	int result = 0;
	for (int i = 0; i < N; i++) {
		for (int k = 0; k < N; k++) {
			int t[5] = {};
			for (int m = 0; m < 5; m++) {
				t[m] = max({ members[i][m],members[k][m]});
			}
			for (int m = 0; m < 5; m++) {
				int tmp = t[m];
				t[m] = sorted[m][N - 1];
				result = max(result, *min_element(t, t + 5));
				t[m] = tmp;
			}

		}
	}

	cout << result << endl;


	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i, r, n) for(int i = r; i < (int)(n); i++)

// 答えで二分探索

int N, X[3030][5];

int getMask(int i, int lim) {
    int res = 0;
    rep(j, 0, 5) if(X[i][j] >= lim) res += 1 << j;
    return res;
}

int cnt[1 << 5];
bool check(int lim) {
    rep(i, 0, 1 << 5) cnt[i] = 0;
    rep(i, 0, N) cnt[getMask(i, lim)]++;
    rep(msk1, 0, 1 << 5) rep(msk2, 0, 1 << 5) rep(msk3, 0, 1 << 5) {
        if((msk1 | msk2 | msk3) == (1 << 5) -1 && cnt[msk1] > 0 && cnt[msk2] > 0 && cnt[msk3] > 0) return true;
    }
    return false;
}

int main() {
    cin >> N;
    rep(i, 0, N) rep(j, 0, 5) cin >> X[i][j];
    int ok = 0, ng = 1000000001;
    while(ok + 1 != ng) {
        int mid = (ok + ng) / 2;
        if(check(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}