#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll INF = 1e17;

int main(){
  int n;
  cin >> n;
  ll a[n][5];
  rep(i,n) rep(j,5) cin >> a[i][j];
  ll l = 0, r = INF;
  while(r-l > 1) {
    ll m = (l + r) / 2;
    vector<vector<int>> bit(n);
    vector<int> val(n);
    vector<int> cnt(1<<5);
    rep(i,n) {
      int b = 0;
      rep(j,5) if(a[i][j] >= m) b += (1<<j);
      val[i] = b;
      rep(k,1<<5) {
        if((b & k) == k) {
          bit[i].push_back(k);
          cnt[k]++;
        }
      }
    }
    int all = (1<<5)-1;
    bool can = false;
    rep(i,n) {
      for(int j = 1; j < n; j++) {
        int res = (val[i] | val[j]);
        res ^= all;
        if(cnt[res]) can = true;
      }
    }
    if(can) l = m;
    else r = m;
  }
  cout << l << endl;
  return 0;
}

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>
#include <map>
#include <set>
#include <functional>

using namespace std;

int N;
vector<int> A, B, C, D, E;

bool binary_check(int x)
{
  set<int> S;

  for (int i = 0; i < N; i++) {
    int s = (A[i] >= x) << 4 |
            (B[i] >= x) << 3 |
            (C[i] >= x) << 2 |
            (D[i] >= x) << 1 |
            (E[i] >= x) << 0;
    S.insert(s);
  }

  for (auto &&a : S) {
    for (auto &&b : S) {
      for (auto &&c : S) {
        if ((a | b | c) == 0b11111) {
          return true;
        }
      }
    }
  }

  return false;
}

int main()
{
  cin >> N;
  A.resize(N);
  B.resize(N);
  C.resize(N);
  D.resize(N);
  E.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i];
  }

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

  while (abs(ng - ok) > 1) {
    x = (ok + ng) / 2;
    if (binary_check(x)) {
      ok = x;
    }
    else {
      ng = x;
    }
  }

  cout << ok << endl;

  return 0;
}
