// clang-format off
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcountll
#define ffs __builtin_ffsll
#define ctz __builtin_ctzll
#define clz __builtin_clz
#define clzll __builtin_clzll
#define all(a) (a).begin(), (a).end()

using namespace std;
using namespace __gnu_pbds;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
// clang-format on

int main() {
    fastio();

    int n;
    cin >> n;
    vec<vi> skill(n, vi(5));
    forn(i, n) {
        forn(j, 5) cin >> skill[i][j];
    }

    vec<vi> p(3);

    int ans = 0;
    int c = 0;
    function<void(int)> dfs = [&](int x) {
        if (x == 5) {
            c++;
            int v = TEN(9) + 10;
            forn(i, 3) { // スキル分担
                int u = 0;
                forn(j, n) {
                    int temp = TEN(9) + 10;
                    for (auto k : p[i]) {
                        chmin(temp, skill[j][k]);
                    }
                    chmax(u, temp);
                }
                chmin(v, u);
            }

            chmax(ans, v);

            return;
        }

        forn(i, 3) {
            p[i].push_back(x);
            dfs(x + 1);
            p[i].pop_back();
        }
    };

    dfs(0);

    cerr << c << endl;

    cout << ans << endl;

    return 0;
}
#include <bits/stdc++.h>
using namespace std;

using ull = unsigned long long int;
using ll = long long int;
using du = double;
using ld = long du;
using vi = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vdu = vector<du>;
using vs = vector<string>;
using vc = vector<char>;

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define sp(x) setprecision(x)<<fixed
#define loop(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pi acos(-1)
#define meme(a,x) memset(a,x,sizeof(a))
#define fout() fflush(stdout)
//debugger

#ifdef KAIZER
#include "debug.h"
#else
#define debug(x...)
#endif
//debugger

bool comp(const int &a, const int &b)
{
    return a>b;
}
bool comp2(const pair<int,set<int>> &a, pair<int,set<int>> &b)
{
    if(a.ss.size()!=b.ss.size()) return a.ss.size()>b.ss.size();
    else return a.ff<b.ff;
}



int main()
{
    FASTIO;
    int n;
    string s;
    cin>>n>>s;
    string p;
    for(auto it: s)
    {
        p.push_back(it);
        {
            if(p.size()>=3)
            {
                if(p[p.size()-1]=='x'&&p[p.size()-2]=='o'&&p[p.size()-3]=='f')
                {
                    loop(i,3) p.pop_back();
                }
            }
        }
    }
    cout<<p.size()<<endl;
}
