#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int inf = 0x3f3f3f3f;
struct node {
  int v, l, r;
} tree[N];
int n, rt, ans;
bool book[N];
map<int, bool> p;
void dfs(int now, int Max, int Min) {
  if (now == -1) return;
  if (tree[now].v > Max && tree[now].v < Min) p[tree[now].v] = true;
  dfs(tree[now].l, Max, min(Min, tree[now].v));
  dfs(tree[now].r, max(Max, tree[now].v), Min);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &tree[i].v, &tree[i].l, &tree[i].r);
    if (~tree[i].l) book[tree[i].l] = true;
    if (~tree[i].r) book[tree[i].r] = true;
  }
  for (int i = 1; i <= n; i++)
    if (!book[i]) {
      rt = i;
      break;
    }
  dfs(rt, -1, inf);
  for (int i = 1; i <= n; i++)
    if (!p[tree[i].v]) ++ans;
  printf("%d", ans);
  return 0;
}
