#include <bits/stdc++.h>
using namespace std;
const int duzo = 100007, inf = 2e9 + 17;
int le[duzo], pr[duzo], v[duzo], par[duzo];
set<int> dob;
void dfs(int w, int nnle = inf, int gzpr = -1) {
  bool cok = true;
  if (v[w] > nnle)
    cok = false;
  else if (v[w] < gzpr)
    cok = false;
  if (cok) dob.insert(v[w]);
  if (le[w] != -1) dfs(le[w], min(nnle, v[w]), gzpr);
  if (pr[w] != -1) dfs(pr[w], nnle, max(gzpr, v[w]));
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, root;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> v[i] >> le[i] >> pr[i];
    par[le[i]] = par[pr[i]] = i;
  }
  for (int i = 1; i <= n; ++i)
    if (!par[i]) root = i;
  dfs(root);
  int ile = 0;
  for (int i = 1; i <= n; ++i)
    if (dob.count(v[i]) == 1) ++ile;
  cout << n - ile;
  return 0;
}
