#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, ans, v[maxn], L[maxn], R[maxn];
bool used[maxn];
set<int> S;
void dfs(int rt, int l, int r) {
  if (v[rt] >= l && v[rt] <= r) S.insert(v[rt]);
  if (L[rt] != -1) dfs(L[rt], l, min(r, v[rt] - 1));
  if (R[rt] != -1) dfs(R[rt], max(l, v[rt] + 1), r);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d", &v[i], &L[i], &R[i]);
    if (L[i] != -1) used[L[i]] = 1;
    if (R[i] != -1) used[R[i]] = 1;
  }
  for (int i = 1; i <= n; i++)
    if (!used[i]) dfs(i, 0, 0x3f3f3f3f);
  for (int i = 1; i <= n; i++) ans += S.count(v[i]);
  printf("%d\n", n - ans);
  return 0;
}
