#include <bits/stdc++.h>
using namespace std;
struct ttr {
  long long v;
  unsigned int l, r, p;
};
ttr tr[100000];
set<long long> ff;
void dfs(unsigned int v, long long ll, long long rr) {
  if (tr[v].v > ll && tr[v].v < rr) {
    ff.insert(tr[v].v);
  }
  if (tr[v].l != -1) dfs(tr[v].l, ll, min(tr[v].v, rr));
  if (tr[v].r != -1) dfs(tr[v].r, max(tr[v].v, ll), rr);
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  unsigned int n;
  cin >> n;
  for (unsigned int i = 0; i < n; ++i) tr[i].l = tr[i].r = tr[i].p = -1;
  for (unsigned int i = 0; i < n; ++i) {
    int l, r;
    cin >> tr[i].v >> l >> r;
    if (l > 0) {
      tr[i].l = l - 1;
      tr[l - 1].p = i;
    }
    if (r > 0) {
      tr[i].r = r - 1;
      tr[r - 1].p = i;
    }
  }
  unsigned int rt = 0;
  while (tr[rt].p != -1) rt = tr[rt].p;
  dfs(rt, -1, 1000000001);
  unsigned int cr = 0;
  for (unsigned int i = 0; i < n; ++i) {
    if (ff.find(tr[i].v) != ff.end()) ++cr;
  }
  cout << n - cr << endl;
  return 0;
}
