#include <bits/stdc++.h>
using namespace std;
vector<tuple<int, int, int> > tree;
unordered_set<int> goods;
vector<int> ok;
void count(int u, int a, int b) {
  if (u < 0) return;
  int v, l, r;
  tie(v, l, r) = tree[u];
  ok[u] = a < v and v < b;
  if (ok[u]) goods.insert(v);
  count(l, a, min(v, b));
  count(r, max(v, a), b);
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int n;
  cin >> n;
  tree.resize(n + 1);
  ok.resize(n + 1);
  vector<int> times(n + 1);
  for (int i = 1; i < (n + 1); ++i) {
    int v, l, r;
    cin >> v >> l >> r;
    if (l != -1) ++times[l];
    if (r != -1) ++times[r];
    tree[i] = {v, l, r};
  }
  int root = -1;
  for (int i = 1; i < (n + 1); ++i)
    if (not times[i]) root = i;
  const int INF = 2e9;
  count(root, -INF, INF);
  for (int u = 1; u < (n + 1); ++u) {
    if (goods.count(get<0>(tree[u]))) ok[u] = 1;
  }
  cout << n - accumulate(ok.begin(), ok.end(), 0) << endl;
}
