#include <bits/stdc++.h>
using namespace std;
int n, ls[100010], rs[100010], v[100010], f[100010];
map<int, bool> s;
void dfs(int x, int l, int r) {
  if (x == -1) return;
  if (l <= v[x] && v[x] <= r) s[v[x]] = 1;
  dfs(ls[x], l, min(r, v[x] - 1));
  dfs(rs[x], max(l, v[x] + 1), r);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &v[i], &ls[i], &rs[i]);
    if (ls[i] != -1) f[ls[i]] = i;
    if (rs[i] != -1) f[rs[i]] = i;
  }
  for (int i = 1; i <= n; i++)
    if (!f[i]) dfs(i, -1e9 - 7, 1e9 + 7);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (s[v[i]]) ans++;
  return printf("%d", n - ans), 0;
}
