#include <bits/stdc++.h>
#define max0(x,y) (x<y?y:x)
#define min0(x,y) (x>y?y:x)
using namespace std;
const double eps=1e-14,down=0.9997;
const int mn=3e3+7;
int n;
int w[mn][6],q1[4],q2[mn];
int fx()
{
	int ans=1e9+7;
    for(int j=1;j<=5;++j)
    {
    	int mx=0;
    	for(int i=1;i<=3;++i)
    	  mx=max0(w[q1[i]][j],mx);
    	ans=min0(ans,mx);
	}
	return ans;
}
int main()
{
    srand(154051);
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
      for(int j=1;j<=5;++j)
        scanf("%d",&w[i][j]);
    q1[1]=1;q1[2]=2;q1[3]=3;
    int cnt=0;
    for(int i=4;i<=n;++i)  q2[++cnt]=i;
    int best,rs;
    best=rs=fx();
    if(n==3)
    {
    	cout<<best;
    	return 0;
	}
    for(double t=13000;t>eps;t*=down)
    {
        int l=rand()%3+1,r=rand()%cnt+1;
        swap(q1[l],q2[r]);
        int tmp=fx();
        if(tmp>best)  best=tmp;
        if(tmp>rs||exp((double)(tmp-rs)/t)*RAND_MAX>rand())  rs=tmp;
        else  swap(q1[l],q2[r]);
    }
    cout<<best;
    return 0;
}
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

inline int in_int(istream& in) {int x; in >> x; return x;}
inline ll in_ll(istream& in) {ll x; in >> x; return x;}
inline string in_str(istream& in) {string x; in >> x; return x;}

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)


class CMADTEAM {
public:
void solve(istream& in, ostream& out) {
    int N = in_int(in);
//    vector A(N, array<int, 5>{});
    vector<array<int, 5>> A(N);

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 5; ++j) {
            A[i][j] = in_ll(in);
        }
    }

    auto check = [&](int x) -> bool{
        set<int> s;
        for (int i = 0; i < N; ++i) {
            int bit = 0;
            for (int j = 0; j < 5; ++j) {
                bit <<= 1;
                if(A[i][j] >= x){
                    bit |= 1;
                }
            }
            s.insert(bit);
        }

        for (int i : s) {
            for (int j : s) {
                for (int k : s) {
                    if((i|j|k) == 31)return true;
                }
            }
        }
        return false;

    };

    int ok = 0;
    int ng = 1e9 + 1;

    while(abs(ok - ng) > 1){
        int cen = (ok + ng) / 2;
        (check(cen) ? ok : ng) = cen;
    }

    out << ok << endl;
}
};

int main() {
	CMADTEAM solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}
