#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int v[maxn], lc[maxn], rc[maxn];
bool h[maxn];
set<int> S;
void d(int o, int l, int r) {
  if (l <= v[o] && v[o] <= r) S.insert(v[o]);
  if (lc[o] != -1) d(lc[o], l, min(r, v[o] - 1));
  if (rc[o] != -1) d(rc[o], max(l, v[o] + 1), r);
}
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    S.clear();
    memset(h, 0, sizeof h);
    for (int i = 1; i <= n; i++) {
      scanf("%d%d%d", v + i, lc + i, rc + i);
      if (lc[i] != -1) h[lc[i]] = 1;
      if (rc[i] != -1) h[rc[i]] = 1;
    }
    for (int i = 1; i <= n; i++) {
      if (!h[i]) d(i, -1, 1e9 + 1);
    }
    int z = 0;
    for (int i = 1; i <= n; i++)
      if (S.find(v[i]) == S.end()) z++;
    printf("%d\n", z);
  }
  return 0;
}
