#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double EPS = 1e-9;
const int INF = 1 << 29;
int const NN = 1e5 + 5;
int pa[NN];
int val[NN];
int L[NN], R[NN];
map<int, bool> mm;
void dfs(int root, int mn, int mx) {
  if (root == -1) return;
  dfs(L[root], min(mn, val[root] - 1), mx);
  if (val[root] <= mn && val[root] >= mx) mm[val[root]] = true;
  dfs(R[root], mn, max(mx, val[root] + 1));
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) pa[i] = -1;
  for (int i = 1; i <= n; ++i) {
    cin >> val[i] >> L[i] >> R[i];
    if (L[i] != -1) {
      pa[L[i]] = i;
    }
    if (R[i] != -1) {
      pa[R[i]] = i;
    }
  }
  int root;
  for (int i = 1; i <= n; ++i) {
    if (pa[i] == -1) root = i;
  }
  dfs(root, 1e9 + 100, -1);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (!mm[val[i]]) ++ans;
  }
  printf("%d", ans);
  ;
  putchar('\n');
  return 0;
}
