#include <cstdio>
#include <algorithm>
using namespace std;
int n,a[5010][11],f[5010][5][41];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=0;j<5;j++)
			scanf("%d",&a[i][j]);
	f[0][0][0]=1e9;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=3;j++)
			for(int k=0;k<32;k++)
			{
				f[i][j][k]=max(f[i][j][k],f[i-1][j][k]);
				if(j)
					for(int s=0;s<32;s++)
						if(!(s&k))
						{
							int minn=1e9;
							for(int l=0;l<5;l++)
								if(s&(1<<l))
									minn=min(minn,a[i][l]);
							f[i][j][s|k]=max(f[i][j][s|k],min(f[i][j-1][k],minn));
						}
			}
	printf("%d",f[n][3][31]);
}
#include <cassert>
#include <limits>

/*
find the maximum integer value that satisfies the given condition,
where if x satisfies it, every y (< x) satisfies it

template parameters:
Integer: an integer type
Function: a function object type

parameters:
a: the lower bound of the possible value
b: the upper bound of the possible value
cond: the function representing the condition
        which take an integer value as an argument
        and return true if the condition is satisfied; false otherwise

return value:
the maximum integer that satisfies the condition

requirements:
there exists a value in [a, b] that satisfies the condition
a <= b
std::numeric_limits<Integer>::min() <= 2*a && 2*b <= std::numeric_limits<Integer>::max()
*/
template <class Integer, class Function>
Integer MaxCond(Integer a, Integer b, Function cond)
{
    // debug
    assert(a <= b);
    assert(a >= std::numeric_limits<Integer>::min() / 2);  // this is sufficient but not necessary
    assert(b <= std::numeric_limits<Integer>::max() / 2);  // this is sufficient but not necessary
    assert(cond(a));  // check the existence of a value in [a, b] that satisfies the condition

    // body
    while (a < b) {
        Integer c = (a + b + 1) / 2;
        if (cond(c)) {
            a = c;
        } else {
            b = c - 1;
        }
    }
    return a;
}


#include <iostream>
#include <vector>
#include <array>

int main()
{
    int n;
    std::cin >> n;
    std::vector<std::array<int, 5>> member(n);
    for (int i = 0; i < n; i++) {
        std::cin >> member[i][0] >> member[i][1] >> member[i][2] >> member[i][3] >> member[i][4];
    }
    int ans = MaxCond(1, 1000000000, [&member, n](int strength) {
        bool possible[32];
        for (int i = 0; i < 32; i++) {
            possible[i] = false;
        }
        for (int i = 0; i < n; i++) {
            int member_possible = 0;
            for (int j = 0; j < 5; j++) {
                if (member[i][j] >= strength) {
                    member_possible |= 1 << j;
                }
            }
            possible[member_possible] = true;
        }
        for (int i = 0; i < 32; i++) {
            if (i == 31 && possible[i]) {
                return true;
            }
            for (int j = i + 1; j < 32; j++) {
                if ((i | j) == 31 && possible[i] && possible[j]) {
                    return true;
                }
                for (int k = j + 1; k < 32; k++) {
                    if ((i | j | k) == 31 && possible[i] && possible[j] && possible[k]) {
                        return true;
                    }
                }
            }
        }
        return false;
    });
    std::cout << ans << std::endl;
}
