#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 10, inf = 1e9 + 20;
int n, v[N], l[N], r[N], par[N], root, ans;
map<int, bool> ok;
void dfs(int i, int L = -inf, int R = +inf) {
  if (L <= v[i] && v[i] <= R) {
    ok[v[i]] = 1;
  }
  if (l[i] != -1) {
    int nR = min(R, v[i] - 1);
    dfs(l[i], L, nR);
  }
  if (r[i] != -1) {
    int nL = max(L, v[i]);
    dfs(r[i], nL, R);
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  memset(par, -1, sizeof par);
  for (int i = 0; i < n; i++) {
    cin >> v[i] >> l[i] >> r[i];
    if (l[i] != -1) {
      par[--l[i]] = i;
    }
    if (r[i] != -1) {
      par[--r[i]] = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (par[i] == -1) {
      root = i;
    }
  }
  dfs(root);
  for (int i = 0; i < n; i++) {
    if (!ok.count(v[i])) {
      ans++;
    }
  }
  cout << ans << '\n';
}
