#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int n, ans;
int v[maxn], l[maxn], r[maxn], p[maxn];
unordered_set<int> correct;
unordered_map<int, int> wrong;
void dfs(int id, int lower, int upper) {
  if (id == -1) return;
  if (v[id] < lower || v[id] > upper)
    wrong[v[id]]++;
  else
    correct.insert(v[id]);
  dfs(l[id], lower, min(upper, v[id] - 1));
  dfs(r[id], max(lower, v[id] + 1), upper);
}
int main() {
  scanf("%d", &n);
  memset(p, -1, sizeof p);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d", &v[i], &l[i], &r[i]);
    if (l[i] != -1) p[l[i]] = i;
    if (r[i] != -1) p[r[i]] = i;
  }
  int root = 0;
  for (int i = 1; i <= n; i++)
    if (p[i] == -1) {
      root = i;
      break;
    }
  ans = 0;
  dfs(root, -1, (int)1e9 + 1);
  for (auto p : wrong)
    if (!correct.count(p.first)) ans += p.second;
  printf("%d\n", ans);
  return 0;
}
