#include <bits/stdc++.h>
using namespace std;
int val[100005], child[100005][2];
bool hasPar[100005];
set<int> res;
void dfs(int node, int lower, int upper) {
  if (node == -1) return;
  if (val[node] <= upper && val[node] >= lower && lower <= upper) {
    res.insert(val[node]);
  }
  dfs(child[node][0], lower, min(val[node], upper));
  dfs(child[node][1], max(val[node], lower), upper);
}
int main() {
  int n, ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &val[i], &child[i][0], &child[i][1]);
    if (child[i][0] != -1) hasPar[child[i][0]] = 1;
    if (child[i][1] != -1) hasPar[child[i][1]] = 1;
  }
  for (int i = 1; i <= n; i++)
    if (!hasPar[i]) dfs(i, 0, 1e9 + 5);
  for (int i = 1; i <= n; i++)
    if (res.find(val[i]) == res.end()) ans++;
  printf("%d\n", ans);
  return 0;
}
