#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
double PI = 4 * atan(1);
map<int, bool> ok;
pair<int, pair<int, int> > vert[100001];
int par[100001], root = 1, ans = 0, n;
void dfs(int node, int lo, int hi) {
  if (lo <= vert[node].first && vert[node].first <= hi)
    ok[vert[node].first] = 1;
  if (vert[node].second.first != -1)
    dfs(vert[node].second.first, lo, min(vert[node].first - 1, hi));
  if (vert[node].second.second != -1)
    dfs(vert[node].second.second, max(vert[node].first + 1, lo), hi);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int v, l, r;
    cin >> v >> l >> r;
    vert[i + 1] = make_pair(v, make_pair(l, r));
    if (l != -1) par[l] = i + 1;
    if (r != -1) par[r] = i + 1;
  }
  while (par[root]) root = par[root];
  dfs(root, 0, 1000000000);
  for (int i = 1; i < n + 1; i++) ans += (1 - ok[vert[i].first]);
  cout << ans;
}
