#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 100000;
int n;
int v[MAXN], l[MAXN], r[MAXN];
int par[MAXN];
int lv[MAXN], rv[MAXN];
bool any[MAXN];
map<int, int> cnt;
void dfs(int at, int LV, int RV) {
  if (LV > RV) return;
  any[at] = true;
  lv[at] = LV, rv[at] = RV;
  if (l[at] != -1) dfs(l[at], LV, min(RV, v[at] - 1));
  if (r[at] != -1) dfs(r[at], max(LV, v[at] + 1), RV);
}
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) {
    scanf("%d%d%d", &v[i], &l[i], &r[i]);
    if (l[i] != -1) --l[i];
    if (r[i] != -1) --r[i];
  }
  for (int i = (0); i < (n); ++i) par[i] = -1;
  for (int i = (0); i < (n); ++i)
    if (l[i] != -1) par[l[i]] = i;
  for (int i = (0); i < (n); ++i)
    if (r[i] != -1) par[r[i]] = i;
  int root = -1;
  for (int i = (0); i < (n); ++i)
    if (par[i] == -1) root = i;
  for (int i = (0); i < (n); ++i) any[i] = false;
  dfs(root, INT_MIN, INT_MAX);
  cnt.clear();
  for (int i = (0); i < (n); ++i) cnt[v[i]]++;
  int found = 0;
  for (int i = (0); i < (n); ++i)
    if (any[i] && lv[i] <= v[i] && v[i] <= rv[i]) found += cnt[v[i]];
  printf("%d\n", n - found);
}
int main() {
  run();
  return 0;
}
