#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, a[N], vis[N], ans;
pair<int, int> p[N];
map<int, int> freq, visited;
void dfs(int u, int L = 0, int R = 1e9) {
  if (u == -2) return;
  if (!visited[a[u]] && a[u] >= L && a[u] <= R)
    ans += freq[a[u]], visited[a[u]] = 1;
  dfs(p[u].first, L, min(a[u], R));
  dfs(p[u].second, max(L, a[u]), R);
}
int main() {
  scanf("%d", &n);
  for (int i = 0, v, l, r; i < n; ++i) {
    scanf("%d%d%d", &v, &l, &r), l--, r--;
    freq[v]++;
    a[i] = v;
    p[i] = make_pair(l, r);
    if (l != -2) vis[l] = 1;
    if (r != -2) vis[r] = 1;
  }
  for (int i = 0; i < n; ++i)
    if (!vis[i]) dfs(i);
  printf("%d\n", n - ans);
}
