#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int val[maxn];
int l[maxn], r[maxn];
int id[maxn];
map<int, int> M;
void dfs(int s, int mi, int ma) {
  if (val[s] > mi && val[s] < ma) M[val[s]] = 1;
  if (l[s] != -1) dfs(l[s], mi, min(ma, val[s]));
  if (r[s] != -1) dfs(r[s], max(mi, val[s]), ma);
}
int main() {
  int n;
  scanf("%d", &n);
  memset(id, 0, sizeof(id));
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &val[i], &l[i], &r[i]);
    if (l[i] != -1) id[l[i]]++;
    if (r[i] != -1) id[r[i]]++;
  }
  int root;
  for (int i = 1; i <= n; ++i) {
    if (!id[i]) root = i;
  }
  int ans = 0;
  dfs(root, -1, INF);
  for (int i = 1; i <= n; ++i)
    if (!M[val[i]]) ans++;
  printf("%d\n", ans);
  return 0;
}
