#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const int maxn = 1e5 + 10;
int n, x = 1, y, z, num = 0, l[maxn], r[maxn], pr[maxn], val[maxn];
map<int, int> m;
void d(int xx, int left, int right) {
  if (xx == -1) return;
  if (val[xx] > left && val[xx] < right) num += m[val[xx]];
  d(l[xx], left, min(right, val[xx]));
  d(r[xx], max(left, val[xx]), right);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &val[i], &y, &z);
    m[val[i]]++, l[i] = y, r[i] = z;
    if (y != -1) pr[y] = i;
    if (z != -1) pr[z] = i;
  }
  while (pr[x]) x = pr[x];
  d(x, -INF, INF);
  printf("%d\n", n - num);
  return 0;
}
