#include <bits/stdc++.h>
int left[1000000], right[1000000], values[1000000];
std::set<int> acc;
void dfs(int root, int l, int r) {
  if (root == -1) return;
  if (l <= values[root] && values[root] <= r) acc.insert(values[root]);
  dfs(left[root], l, std::min(r, values[root]));
  dfs(right[root], std::max(l, values[root]), r);
}
int main() {
  int n;
  scanf("%d", &n);
  std::unordered_map<int, int> parent;
  for (int i = 1; i <= n; i++) parent[i] = -1;
  for (int i = 1; i <= n; i++) {
    int v, l, r;
    scanf("%d %d %d", &v, &l, &r);
    values[i] = v;
    left[i] = l;
    right[i] = r;
    if (l > 0) parent[l] = i;
    if (r > 0) parent[r] = i;
  }
  int root;
  for (int i = 0; i <= n; i++)
    if (parent[i] == -1) {
      root = i;
      break;
    }
  dfs(root, -1, 999999999);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (acc.find(values[i]) == acc.end()) ans++;
  printf("%d\n", ans);
}
