#include <bits/stdc++.h>
using namespace std;
long long int paw(long long int a, long long int b);
int val[110000], l[110000], r[110000], ir[110000], ans = 0;
map<int, int> fa;
int dfs(int v, int lo, int up) {
  map<int, int>::iterator itr;
  if (val[v] < lo || val[v] > up) {
    itr = fa.find(val[v]);
    if (itr == fa.end())
      fa[val[v]] = 1;
    else if (itr->second > 0)
      fa[val[v]] += 1;
  } else
    fa[val[v]] = 0;
  if (l[v] > 0) dfs(l[v], lo, min(up, val[v]));
  if (r[v] > 0) dfs(r[v], max(lo, val[v]), up);
  return 0;
}
int main() {
  int n, rt = 0, i;
  cin >> n;
  for (i = 1; i < n + 1; i++) {
    cin >> val[i] >> l[i] >> r[i];
    if (l[i] != -1) ir[l[i]] = 1;
    if (r[i] != -1) ir[r[i]] = 1;
  }
  for (i = 1; i < n + 1; i++)
    if (ir[i] == 0) rt = i;
  dfs(rt, -1 * 1000000020, 1000000020);
  map<int, int>::iterator itr;
  for (itr = fa.begin(); itr != fa.end(); itr++) ans += itr->second;
  cout << ans << endl;
  return 0;
}
