#include <bits/stdc++.h>
using namespace std;
int n, p[100001], l[100001], r[100001], lc, rc, root, val[100001], ans;
map<int, int> found;
inline void traverse(int node, int mini, int maxi, bool l_or_r) {
  if (node == -1) return;
  if (node == root) {
    traverse(l[node], mini, val[node], 0);
    traverse(r[node], val[node], maxi, 1);
    return;
  }
  if (l_or_r) {
    if ((val[node] > val[p[node]]) && (val[node] < maxi) && (val[node] > mini))
      found[val[node]] = 1;
  } else {
    if ((val[node] < val[p[node]]) && (val[node] < maxi) && (val[node] > mini))
      found[val[node]] = 1;
  }
  traverse(l[node], mini, min(maxi, val[node]), 0);
  traverse(r[node], max(mini, val[node]), maxi, 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> val[i] >> lc >> rc;
    l[i] = lc;
    r[i] = rc;
    if (lc == -1 && rc == -1)
      root = i;
    else {
      if (lc != -1) p[lc] = i;
      if (rc != -1) p[rc] = i;
    }
  }
  while (p[root] > 0) root = p[root];
  found[val[root]] = 1;
  traverse(root, -2000000000, 2000000000, 0);
  for (int i = 1; i <= n; i++) {
    if (found[val[i]] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
