#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  int zf = 1;
  char ch = ' ';
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') zf = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * zf;
}
int mp[100005];
map<int, int> mp2;
struct Node {
  int l, r;
  int val;
} nodes[100005];
int node_cnt = 0;
int ans = 0;
void DFS(int node, int l, int r) {
  if (!mp2[nodes[node].val]) {
    if (nodes[node].val < l || nodes[node].val > r)
      ++ans;
    else
      mp2[nodes[node].val] = 1;
  }
  if (nodes[node].l != -1)
    DFS(nodes[node].l, l, ((nodes[node].val < r) ? nodes[node].val : r));
  if (nodes[node].r != -1)
    DFS(nodes[node].r, ((nodes[node].val > l) ? nodes[node].val : l), r);
}
int main() {
  int n = read();
  for (int i = 0; i < n; ++i) {
    nodes[++node_cnt].val = read();
    nodes[node_cnt].l = read(), nodes[node_cnt].r = read();
    mp[nodes[node_cnt].l] = 1, mp[nodes[node_cnt].r] = 1;
  }
  int rt = 1;
  for (int i = 1; i <= node_cnt; ++i) {
    if (mp[i] != 1) {
      rt = i;
      break;
    }
  }
  DFS(rt, -1, 1e9 + 10);
  ans = 0;
  DFS(rt, -1, 1e9 + 10);
  printf("%d", ans);
  return 0;
}
