
/* {{{ */
#include <bits/stdc++.h>
using namespace std;
#ifdef __LOCAL
#include <prettyprint.hpp>
#define debug(a) cerr << "[\033[33mDEBUG\033[m] " << (#a) << ": " << (a) << endl
#else
#define debug(s) cerr << "[\033[33mDEBUG\033[m] local only" << endl
#endif
using ll = long long;
template <class T> using vec = vector<T>;
#define endl "\n"
#define INF (int)1e9
#define LINF (long long)1e12
#define MOD (int)1e9+7
#define _rep(i,_a,_b,a,b,...) for (int i=(a), lim##i=(b); i<lim##i; i++)
#define rep(i, ...) _rep(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define _rrep(i,_a,_b,a,b,...) for (int i=(a), lim##i=(b); i>=lim##i; i--)
#define rrep(i, ...) _rrep(i, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, 0)
#define each(e, c) for (auto &e: c)
#define all(v) begin(v), end(v)
#define popcount __builtin_popcount
template <class T> bool chmin(T& a, const T& b) { return a>b?a=b,true:false; }
template <class T> bool chmax(T& a, const T& b) { return a<b?a=b,true:false; }
void init()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}
/* }}} */

int n;
vec<vec<ll>> capa;

bool check(ll x)
{
  vec<bool> can(1 << 5, false);
  each(c, capa)
  {
    int bit = 0;
    rep(i, 5)
    {
      if (c[i] >= x) bit |= 1 << i;
    }
    can[bit] = true;
  }
  rep(i, 1 << 5) rep(j, i + 1) rep(k, j + 1)
  {
    if (can[i] && can[j] && can[k]
        and (i | j | k) == (1 << 5) - 1)
    {
      return true;
    }
  }
  return false;
}

int main()
{
  init();

  cin >> n;
  capa.resize(n);
  rep(i, n)
  {
    capa[i].resize(5);
    rep(j, 5) cin >> capa[i][j];
  }

  ll ok = -1, ng = LINF;
  while (ng - ok > 1)
  {
    ll mid = (ok + ng) / 2;
    if (check(mid)) ok = mid;
    else ng = mid;
  }

  cout << ok << endl;
}


#include <bits/stdc++.h>
using namespace std;
int a[3001][5];
int n;
bool valid(int req) {
    set<int> mask;
    for(int i = 0; i < n; i++) {
        int bits = 0;
        for(int j = 0; j < 5; j++) {
            if(a[i][j] >= req)
                bits |= (1 << j);
        }
        mask.insert(bits);
    }
    for (auto i : mask) {
        for (auto j : mask) {
            for (auto k : mask) {
                if((i | j | k) == 31)
                    return true;
            }
        }
    }
    return false;
}
void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 5; j++) {
            cin >> a[i][j];
        }
    }
    int l = 0, r = 1000000001;
    while (l + 1 < r) {
        int mid = l + (r - l) / 2;
        if (valid(mid)) {
            l = mid;
        }
        else {
            r = mid;
        }
    }
    cout << l;
}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cout << fixed << setprecision(10);
    for (int i = 0; i < t; i++) {
        solve();
    }
    return 0;
}

