#include <bits/stdc++.h>
int n, ans = 0;
struct tree {
  std::map<int, int> mp;
  struct node {
    int ls, rs, val, fa, sz;
  };
  node f[100005];
  int rt;
  void calc(int v) {
    if (f[v].ls) calc(f[v].ls);
    if (f[v].rs) calc(f[v].rs);
    f[v].sz = 1 + f[f[v].ls].sz + f[f[v].rs].sz;
  }
  void dfs(int v, int l, int r) {
    int s = 0;
    if (l <= f[v].val && f[v].val <= r) mp[f[v].val] = 1;
    if (f[v].ls) dfs(f[v].ls, l, std::min(r, f[v].val - 1));
    if (f[v].rs) dfs(f[v].rs, std::max(l, f[v].val + 1), r);
  }
  int solve() {
    int ans = 0;
    dfs(rt, 0, 1000000000);
    for (int i = 1; i <= n; i++) ans = ans + !mp[f[i].val];
    return ans;
  }
};
tree t;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int v, l, r;
    scanf("%d%d%d", &v, &l, &r);
    if (l != -1) {
      t.f[i].ls = l;
      t.f[l].fa = i;
    }
    if (r != -1) {
      t.f[i].rs = r;
      t.f[r].fa = i;
    }
    t.f[i].val = v;
  }
  for (int i = 1; i <= n; i++)
    if (!t.f[i].fa) t.rt = i;
  t.calc(t.rt);
  ans = t.solve();
  printf("%d\n", ans);
  return 0;
}
