#include <bits/stdc++.h>
using namespace std;
const int N = 101010;
int n;
int lson[N], rson[N], val[N];
int ind[N];
int ans;
set<int> vis;
void dfs(int rt, int l, int r) {
  if (rt == -1) return;
  int v = val[rt];
  if (l <= v && v <= r || vis.count(v)) {
    vis.insert(v);
  }
  if (v <= l) {
    dfs(rson[rt], l, r);
  } else if (v > r) {
    dfs(lson[rt], l, r);
  } else {
    dfs(lson[rt], l, v);
    dfs(rson[rt], v, r);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i < (n + 1); i++) {
    scanf("%d%d%d", val + i, lson + i, rson + i);
    if (lson[i] != -1) ind[lson[i]]++;
    if (rson[i] != -1) ind[rson[i]]++;
  }
  int rt = -1;
  for (int i = (1); i < (n + 1); i++)
    if (ind[i] == 0) rt = i;
  dfs(rt, INT_MIN, INT_MAX);
  for (int i = (1); i < (n + 1); i++) ans += vis.count(val[i]);
  printf("%d\n", n - ans);
  return 0;
}
