#include <bits/stdc++.h>
using namespace std;
set<int> sq;
int up[100005];
int L[100005];
int R[100005];
int que[100005];
void dfs(int l, int r, int x) {
  if (l > r) return;
  if (que[x] >= l && que[x] <= r) sq.insert(que[x]);
  if (~L[x]) dfs(l, min(que[x] - 1, r), L[x]);
  if (~R[x]) dfs(max(que[x] + 1, l), r, R[x]);
}
int main() {
  memset(up, 0, sizeof(up));
  memset(L, -1, sizeof(L));
  memset(R, -1, sizeof(R));
  int n, i;
  scanf("%d", &n);
  int l0, r0;
  for (i = 1; i <= n; i++) {
    scanf("%d%d%d", que + i, L + i, R + i);
    up[L[i]] = up[R[i]] = i;
  }
  for (i = 1; i <= n; i++) {
    if (up[i]) continue;
    dfs(-1, 1000000010, i);
    break;
  }
  int cnt = 0;
  for (i = 1; i <= n; i++)
    if (!sq.count(que[i])) cnt++;
  printf("%d", cnt);
  return 0;
}
