#include <bits/stdc++.h>
using namespace std;
int n, a, b, c, t[1000111];
pair<int, int> dr[1000111];
int wyn;
bool mastarego[1000111];
int start;
map<int, int> mapa;
void dfs(int w, int l, int p) {
  if (t[w] >= l && t[w] <= p) mapa[t[w]] = 1;
  if (dr[w].first != -1) {
    dfs(dr[w].first, l, min(t[w] - 1, p));
  }
  if (dr[w].second != -1) {
    dfs(dr[w].second, max(l, t[w] + 1), p);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &a, &b, &c);
    t[i] = a;
    dr[i] = make_pair(b, c);
    mastarego[b] = true;
    mastarego[c] = true;
  }
  for (int i = 1; i <= n; i++)
    if (!mastarego[i]) {
      start = i;
      break;
    }
  dfs(start, 0, 1000000001);
  for (int i = 1; i <= n; i++) {
    if (mapa[t[i]] == 1) wyn++;
  }
  printf("%d\n", n - wyn);
  return 0;
}
