#include <bits/stdc++.h>
using namespace std;
const int T = 100042;
const int INF = 2e9;
int n;
bool is_root[T];
int v[T];
int l[T];
int r[T];
int ans;
unordered_map<int, int> cp;
unordered_map<int, bool> ok;
void DFS(int u, int l_bound, int u_bound) {
  if (u == -1) return;
  if (l_bound <= v[u] && v[u] <= u_bound) ok[v[u]] = true;
  DFS(l[u], l_bound, min(u_bound, v[u]));
  DFS(r[u], max(l_bound, v[u]), u_bound);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) is_root[i] = true;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &v[i], &l[i], &r[i]);
    cp[v[i]]++;
    if (l[i] != -1) is_root[l[i]] = false;
    if (r[i] != -1) is_root[r[i]] = false;
  }
  int root = 0;
  for (int i = 1; i <= n; i++)
    if (is_root[i]) root = i;
  DFS(root, -INF, INF);
  for (int i = 1; i <= n; i++)
    if (!ok[v[i]]) ans++;
  printf("%d\n", ans);
  return 0;
}
