#include <bits/stdc++.h>
using namespace std;
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int flag[100001];
int a[100001][2], v[100001];
void dfs(int x, int left, int right) {
  if (flag[x] != -1) return;
  if (v[x] < right)
    flag[x] = 0;
  else if (v[x] >= left)
    flag[x] = 0;
  else
    flag[x] = 1;
  int lefti = min(left, v[x]);
  int righti = max(right, v[x]);
  if (a[x][0] != -1) dfs(a[x][0], lefti, right);
  if (a[x][1] != -1) dfs(a[x][1], left, righti);
  return;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n + 1; i++) flag[i] = -1;
  set<int> s;
  for (int i = 0; i < n; i++) s.insert(i + 1);
  for (int i = 1; i <= n; i++) {
    int val, l, r;
    cin >> val >> l >> r;
    a[i][0] = l, a[i][1] = r, v[i] = val;
    if (s.find(l) != s.end()) s.erase(l);
    if (s.find(r) != s.end()) s.erase(r);
  }
  set<int>::iterator it;
  int root;
  for (it = s.begin(); it != s.end(); ++it) root = *it;
  dfs(root, 1000000007, 0);
  set<int> vv;
  int count = 0;
  for (int i = 1; i < n + 1; i++)
    if (flag[i]) vv.insert(v[i]);
  for (int i = 1; i < n + 1; i++)
    if (flag[i] || vv.find(v[i]) != vv.end()) count++;
  cout << (n - count) << "\n";
}
