#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
vector<int>to[100005];
int dp[100005];
int sz[100005];

void dfs(int v, int p = -1) {
	int csub = 0;
	dp[v] = 1;
	sz[v] = 1;
	vector<int>c;
	for (int e : to[v]) {
		if (p == e) {
			continue;
		}
		dfs(e, v);
		sz[v] += sz[e];
		int num = dp[e];
		if ((num < 0) && (0 == (sz[e] % 2))) {
			//case1
			dp[v] += num;
		}
		else if ((num >= 0) && (0 == (sz[e] % 2))) {
			//case2
			csub += num;
		}
		else {
			//case3
			c.push_back(num);
		}
	}
	sort(all(c));
	c.push_back(csub);
	rep(i, c.size()) {
		if (0 == i % 2) {
			dp[v] += c[i];
		}
		else {
			dp[v] -= c[i];
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	rep(i, N - 1) {
		int p;
		cin >> p;
		p--;
		to[i + 1].push_back(p);
		to[p].push_back(i + 1);
	}
	dfs(0);
	int ans = (dp[0] + N) / 2;
	cout << ans << endl;
	return 0;
}
// Problem: C - MAD TEAM
// Contest: AtCoder - ZONe Energy Programming Contest
// URL: https://atcoder.jp/contests/zone2021/tasks/zone2021_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define pb push_back
#define mp make_pair
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;
const int MAX_N = 3002;

int n;
ll a[MAX_N][5];

void solve()
{
	int lo=1, hi=1e9+1;
	while(lo+1<hi){
		int mid=(lo+hi)/2;
		vector<int> b(32, 0);
		for(int i=0;i<n;++i){
			int f = 0;
			for(int j=0;j<5;++j)if(a[i][j]>=mid) f|=(1<<j);
			b[f]++;
		}
		bool found=false;
		for(int i=0;i<32;++i)if(b[i])for(int j=i;j<32;++j)if(b[j])
		for(int k=j;k<32;++k)if(b[k]){
			if((i|j|k) == 31 && b[i]+b[j]+b[k]>=3) found=true;
		}
		if(!found) hi=mid;
		else lo=mid;
	}
	cout<<lo<<'\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> n;
	for(int i=0;i<n;++i)for(int j=0;j<5;++j)cin>>a[i][j];
	solve();
	return 0;
}