#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int v[MAXN], p[MAXN], l[MAXN], r[MAXN];
vector<int> va[MAXN];
set<int> s;
int ans;
void DFS(int u, int minv, int maxv) {
  if (u == 0) return;
  if (minv <= v[u] && v[u] <= maxv) s.insert(v[u]);
  DFS(l[u], minv, min(maxv, v[u]));
  DFS(r[u], max(minv, v[u]), maxv);
  return;
}
int main() {
  int n, root;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &v[i], &l[i], &r[i]);
    l[i] = max(l[i], 0);
    r[i] = max(r[i], 0);
    p[l[i]] = p[r[i]] = i;
  }
  for (int i = 1; i <= n; ++i)
    if (p[i] == 0) root = i;
  DFS(root, INT_MIN, INT_MAX);
  for (int i = 1; i <= n; ++i)
    if (s.count(v[i]) == 0) ans++;
  printf("%d\n", ans);
  return 0;
}
