#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
int n;
int root;
VVI adj;
bool findrecursive(int v, int x) {
  int data = adj[v][0], left = adj[v][1], right = adj[v][2];
  if (data == x) return true;
  if (left < 0 && right < 0) return false;
  bool ret = false;
  if (x < data && left > 0)
    ret |= findrecursive(left, x);
  else if (x > data && right > 0)
    ret |= findrecursive(right, x);
  return ret;
}
set<int> found;
void dfs(int here, int lo, int hi) {
  if (here == -1) return;
  int val = adj[here][0], left = adj[here][1], right = adj[here][2];
  if (val >= lo && val <= hi) found.insert(val);
  dfs(left, lo, min(hi, val));
  dfs(right, max(lo, val), hi);
}
int solve() {
  if (n == 1) return 0;
  VI cnt(n + 1);
  adj = VVI(n + 1, VI(3, -1));
  for (int i = 1; i <= n; ++i) {
    int d, l, r;
    cin >> d >> l >> r;
    if (l > 0) ++cnt[l];
    if (r > 0) ++cnt[r];
    adj[i][0] = d, adj[i][1] = l, adj[i][2] = r;
  }
  for (int i = 1; i <= n; ++i)
    if (!cnt[i]) {
      root = i;
      break;
    }
  dfs(root, INT_MIN, INT_MAX);
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if (found.count(adj[i][0]) == 0) ++ans;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  cout << solve() << endl;
  return 0;
}
