    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    using P=pair<ll,ll>;
    const int INF=1001001001;
    const int mod=1e9+7;
    
    void solve(){
      int n;cin>>n;
      vector<vector<int>>t(n,vector<int>(5));
      rep(i,n){
        rep(j,5){cin>>t[i][j];}
      }
      vector<int>mx(1<<5);
      rep(mask,1<<5){
        rep(i,n){
          int tmp=INF;
          rep(j,5){
            if((~mask>>j)&1){continue;}
            chmin(tmp,t[i][j]);
          }
          chmax(mx[mask],tmp);
        }
      }
      int ans=0;
      rep(i,1<<5){
        rep(j,1<<5){
          rep(k,1<<5){
            if((i|j|k)!=(1<<5)-1){continue;}
            int tmp=min({mx[i],mx[j],mx[k]});
            chmax(ans,tmp);
          }
        }
      }
      cout<<ans<<endl;
    }
    int main(){
      solve();
      return 0;
    }


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i,n) for(int i=0;i<n;i++)
#define f(i, a, b) for(int i=a;i<b;i++)
#define vi vector<int>
#define pb push_back
#define MOD 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#define setzero(a) memset(a,0,sizeof(a))
ll digits(ll n)
{
    return floor(log10(double(n))) + 1;
}
void faster()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
ll modularExponentiation(ll x,ll n,ll M)
{
    ll result = 1;
    while(n>0)
    {
        if(n % 2 ==1)
        {
            result = ((result%M)*(x%M))%M;
        }
        x  = ((x%M)*(x%M))%M;
        n = n/2;
    }
    return result%M;
}
ll d, x, y;
void extendedEuclid(ll A, ll B)
{
    if(B == 0)
    {
        d = A;
        x = 1;
        y = 0;
    }
    else
    {
        extendedEuclid(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}
// DP solution for nCr
ll nCrModp(ll n, ll r)
{
    if (r > n - r)
        r = n - r;
    ll C[r + 1];
    memset(C, 0, sizeof(C));

    C[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i,r); j > 0; j--)
        {
            C[j] = (C[j] + C[j - 1]);
        }
    }
    return C[r];
}
ll modInverse(ll A, ll M)
{
    extendedEuclid(A,M);
    return (x%M+M)%M;    //x may be negative
}
// primefactors[a] = primefactors[a/primedivisor[a]] + 1
ll sumdigits(ll n)
{
    ll ans = 0;
    while(n>0)
    {
        ans += n%10;
        n = n/10;
    }
    return ans;
}
ll less_power2(ll n)
{
    ll i = 1;
    while(i*2<=n)
    {
        i = i*2;
    }
    return i;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
}

vector<int>adj[101];
int visited[100];
void dfs(string ans,int v,int d)
{
    ans += v + '0';
    if(v==d)
    {
        cout<<ans<<endl;
        return;
    }
    visited[v] = 1;
    for(auto x : adj[v])
    {
        if(visited[x]==0)
        {
            dfs(ans,x,d);
        }
    }
    visited[v] = 0;
}
bool fun(int arr[],int in, bool ma, int n)
{
    if(arr[in])
        in++;
    if(in==n)
        return ma;
    fun(arr,in,ma,n);
}
int main()
{
    ll n;
    cin>>n;
    n--;
    ll ans = nCrModp(n,11);
    cout<<ans;
}
