#include <bits/stdc++.h>
using namespace std;
int n, x[100001], l[100001], r[100001], z;
bool v[100001];
set<int> o;
void d(int a, int b, int c) {
  if (x[a] >= b && x[a] <= c) o.insert(x[a]);
  if (l[a] != -1) d(l[a], b, min(c, x[a] - 1));
  if (r[a] != -1) d(r[a], max(b, x[a] + 1), c);
}
int main() {
  scanf("%d", &n);
  for (int a = 1; a <= n; a++) {
    scanf("%d%d%d", x + a, l + a, r + a);
    if (l[a] != -1) v[l[a]] = 1;
    if (r[a] != -1) v[r[a]] = 1;
  }
  for (int a = 1; a <= n; a++)
    if (!v[a]) d(a, 0, 1000000000);
  for (int a = 1; a <= n; a++)
    if (o.find(x[a]) == o.end()) z++;
  printf("%d\n", z);
  return 0;
}
