#include <bits/stdc++.h>
using namespace std;
int N, v[100010], l[100010], r[100010];
bool g[100010];
map<int, bool> mp;
void dfs(int nod, int L, int R) {
  if (nod == -1 || L > R) return;
  int res = 0;
  if (v[nod] >= L && v[nod] <= R) mp[v[nod]] = 1;
  dfs(l[nod], L, min(R, v[nod] - 1));
  dfs(r[nod], max(v[nod] + 1, L), R);
}
int main() {
  cin >> N;
  int i;
  for (i = 1; i <= N; i++) {
    cin >> v[i] >> l[i] >> r[i];
    if (l[i] != -1) g[l[i]] = 1;
    if (r[i] != -1) g[r[i]] = 1;
  }
  for (i = 1; i <= N; i++)
    if (!g[i]) dfs(i, 0, (1 << 30));
  int res = 0;
  for (i = 1; i <= N; i++)
    if (mp[v[i]] == 0) res++;
  cout << res << "\n";
  return 0;
}
