#include<bits/stdc++.h>
using namespace std;
typedef struct tree{
int left;
int right;
}tree;
int ans=1;
tree t[1000001];
int dfs(tree a)
{
if(a.left==0&&a.right==0)
{
return ans;
}
ans++;
dfs(t[a.left]);
dfs(t[a.right]);
}
int main()
{
int n=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int a,b=0;
scanf("%d%d",&a,&b);
t[i].left=a;
t[i].right=b;
}
int c=dfs(t[1]);
printf("%d",c);
return 0;
}