#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int n, a[100100], b[100100], son[100100][2], f[100100], g[100100];
bool root[100100], ok[100100];
void dfs(int x) {
  if (f[x] > a[x] && g[x] < a[x]) ok[a[x]] = 1;
  for (int i = 0; i <= 1; i++) {
    int y = son[x][i];
    if (y == -1) continue;
    f[y] = f[x], g[y] = g[x];
    if (i == 0)
      f[y] = min(f[y], a[x]);
    else
      g[y] = max(g[y], a[x]);
    dfs(y);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) root[i] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d", &a[i], &son[i][0], &son[i][1]);
    b[i] = a[i];
    if (son[i][0] != -1) root[son[i][0]] = 0;
    if (son[i][1] != -1) root[son[i][1]] = 0;
  }
  sort(b + 1, b + n + 1);
  int m = unique(b + 1, b + n + 1) - b - 1;
  for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + m + 1, a[i]) - b;
  for (int i = 1; i <= n; i++) {
    if (root[i]) f[i] = inf, g[i] = 0, dfs(i);
  }
  int ans = n;
  for (int i = 1; i <= n; i++)
    if (ok[a[i]]) ans--;
  printf("%d\n", ans);
  return 0;
}
