#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 50;
long long int n1[N], n2[N], t = 0, visited[N], h[N], dis[N], e[N][2], val[N],
                            par[N];
long long inf = LLONG_MAX / 2;
map<int, int> mp, mark;
void dfs(int v, long long int baze1, long long int baze2) {
  if (val[v] >= baze1 and val[v] <= baze2) {
    mp[val[v]] = 1;
  }
  if (e[v][0] != -1) {
    dfs(e[v][0], baze1, min(baze2, val[v]));
  }
  if (e[v][1] != -1) {
    dfs(e[v][1], max(baze1, val[v]), baze2);
  }
}
int main() {
  int n;
  cin >> n;
  fill(par, par + n + 1, -1);
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> val[i] >> x >> y;
    e[i][0] = x;
    e[i][1] = y;
    if (x != -1) par[x] = i;
    if (y != -1) par[y] = i;
  }
  int root = 0;
  for (int i = 1; i <= n; i++) {
    if (par[i] == -1) {
      root = i;
    }
  }
  dfs(root, -1 * inf, inf);
  for (int i = 1; i <= n; i++) {
    if (mp[val[i]] == 0) {
      t++;
      mark[val[i]] = 1;
    }
  }
  cout << t << "\n";
}
