#include <bits/stdc++.h>
using namespace std;
struct node {
  int val, l, r;
} a[100010];
int rt, n;
bool to[100010];
map<int, bool> ma;
vector<int> v;
void dfs(int u, int maxx, int minn) {
  if (u == -1) return;
  if (a[u].val > maxx && a[u].val < minn) ma[a[u].val] = true;
  dfs(a[u].l, maxx, min(a[u].val, minn));
  dfs(a[u].r, max(a[u].val, maxx), minn);
  return;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &a[i].val, &a[i].l, &a[i].r);
    if (a[i].l != -1) to[a[i].l] = true;
    if (a[i].r != -1) to[a[i].r] = true;
  }
  for (int i = 1; i <= n; i++)
    if (to[i] == false) rt = i;
  dfs(rt, -1, 1e9 + 1);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (ma[a[i].val] == false) ans++;
  cout << ans;
  return 0;
}
