#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
int const maxn = 100005;
pair<int, int> gr[maxn];
int val[maxn];
set<int> canfind;
void dfs(const int v, const int l, const int r) {
  if (l <= val[v] && val[v] <= r) canfind.insert(val[v]);
  if (gr[v].first != -1) dfs(gr[v].first, l, min(val[v] - 1, r));
  if (gr[v].second != -1) dfs(gr[v].second, max(l, val[v] + 1), r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  set<int> verts;
  for (int i = 1; i <= n; ++i) verts.insert(i);
  for (int i = 1; i <= n; ++i) {
    cin >> val[i] >> gr[i].first >> gr[i].second;
    if (verts.count(gr[i].first)) verts.erase(gr[i].first);
    if (verts.count(gr[i].second)) verts.erase(gr[i].second);
  }
  dfs(*verts.begin(), -1, 1000000009);
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if (canfind.find(val[i]) == canfind.end()) ++ans;
  cout << ans << endl;
}
