rt
#include<bits/stdc++.h>
#define endl "\n"
#define mp make_pair
#define int long long
#define ull unsigned long long
using namespace std;
const long long mod=1000000001;
const long long P=201;
int n,m;
struct node{
map<int,int>c;
int x;
}a[2000001];
vector<int>b[2000001];
int fa[2000001];
int dfs(int x)
{
int ans=0;
for(int i=0;i<b[x].size();i++)
{
ans+=dfs(b[x][i]);
}
int k=-1,cnt=1;
for(auto y:a[x].c)
{
if(k==-1)k=y.second;
if(k!=y.second)cnt=0;
a[fa[x]].c[y.first]+=y.second;
}
return cnt+ans;
}
signed main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
cin>>n;
int c,f;
for(int i=1;i<=n;i++)
{
cin>>c>>f;
fa[i]=f;
b[f].push_back(i);
a[i].c[c]=1;
}
cout<<dfs(1)<<endl;
return 0;
exit(0);
}