#include <bits/stdc++.h>
using namespace std;
const unsigned long long p = 19260817;
const unsigned long long p2 = 20111203;
const long long maxn = 1e10;
long long T;
long long ls[100000 + 5], rs[100000 + 5];
long long val[100000 + 5];
long long mark[100000 + 5];
unordered_map<long long, int> mp;
long long ans = 0;
void dfs(long long now, long long l, long long r) {
  if (l > r) return;
  if (val[now] <= r && val[now] >= l) {
    mp[val[now]]++;
    if (ls[now] != -1) dfs(ls[now], l, val[now] - 1);
    if (rs[now] != -1) dfs(rs[now], val[now] + 1, r);
  } else if (val[now] > r) {
    if (ls[now] != -1) dfs(ls[now], l, r);
  } else if (val[now] < l) {
    if (rs[now] != -1) dfs(rs[now], l, r);
  }
  return;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> T;
  for (int i = 1; i <= T; i++) {
    long long tmpl, tmpr, tmp;
    cin >> tmp >> tmpl >> tmpr;
    ls[i] = tmpl;
    rs[i] = tmpr;
    val[i] = tmp;
    if (tmpl != -1) mark[tmpl] = 1;
    if (tmpr != -1) mark[tmpr] = 1;
  }
  long long root;
  for (int i = 1; i <= T; i++)
    if (mark[i] == 0) root = i;
  dfs(root, -1, maxn);
  for (int i = 1; i <= T; i++)
    if (mp.find(val[i]) == mp.end()) ans++;
  cout << ans;
}
