#include <bits/stdc++.h>
using namespace std;
struct tree_node {
  int val, l, r;
  tree_node(){};
  tree_node(int a, int b, int c) {
    val = a;
    l = b;
    r = c;
  };
} node[100005];
bool deg[100005];
void search(int cur, int rl, int rr, map<int, bool> &mp) {
  if (node[cur].val > rr || node[cur].val < rl) {
    mp[node[cur].val] |= false;
  } else
    mp[node[cur].val] = true;
  int nr = min(rr, node[cur].val), nl = max(rl, node[cur].val);
  if (node[cur].l != -1) search(node[cur].l, rl, nr, mp);
  if (node[cur].r != -1) search(node[cur].r, nl, rr, mp);
}
int main() {
  int n, a, b, c;
  while (cin >> n) {
    map<int, int> cnt;
    for (int i = 1; i <= n; i++) {
      scanf("%d%d%d", &a, &b, &c);
      node[i] = tree_node(a, b, c);
      if (b != -1) deg[b] = true;
      if (c != -1) deg[c] = true;
      cnt[a]++;
    }
    int root;
    for (int i = 1; i <= n; i++)
      if (!deg[i]) root = i;
    int res = 0;
    map<int, bool> mp;
    search(root, 0, 1e9, mp);
    for (map<int, bool>::iterator it = mp.begin(); it != mp.end(); it++) {
      if (!(*it).second) res += cnt[(*it).first];
    }
    cout << res << endl;
  }
  return 0;
}
