#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct point {
  int val, l, r;
} a[N];
map<int, int> mp;
bool vis[N];
void dfs(int u, int lt, int rt) {
  if (a[u].val >= lt && a[u].val <= rt) {
    mp[a[u].val] = 0;
  }
  if (a[u].l != -1) dfs(a[u].l, lt, min(rt, a[u].val - 1));
  if (a[u].r != -1) dfs(a[u].r, max(lt, a[u].val + 1), rt);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &a[i].val, &a[i].l, &a[i].r);
    mp[a[i].val]++;
    if (a[i].l != -1) vis[a[i].l] = true;
    if (a[i].r != -1) vis[a[i].r] = true;
  }
  int root;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) root = i;
  dfs(root, -2000000000, 2000000000);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (mp[a[i].val] > 0) ans++;
  cout << ans << endl;
  return 0;
}
