#include <bits/stdc++.h>
using namespace std;
int MAXN = 100001;
int MINV = 0, MAXV = 1000 * 1000 * 1000;
vector<pair<int, int>> range(MAXN), t(MAXN);
vector<int> val(MAXN);
vector<int> p(MAXN, -1);
unordered_map<int, bool> m;
int n, minv, maxv;
inline bool validrange(int v) { return range[v].first <= range[v].second; }
void dfs(int v) {
  int minv = range[v].first, maxv = range[v].second;
  if (range[v].first <= val[v] && val[v] <= range[v].second) m[val[v]] = true;
  int left = t[v].first, right = t[v].second;
  if (left != -1) {
    range[left] = make_pair(minv, min(maxv, val[v]));
    if (validrange(left)) dfs(t[v].first);
  }
  if (right != -1) {
    range[right] = make_pair(max(minv, val[v]), maxv);
    if (validrange(right)) dfs(t[v].second);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int v, l, r;
    cin >> v >> l >> r;
    if (l != -1) p[--l] = i;
    if (r != -1) p[--r] = i;
    val[i] = v;
    t[i] = make_pair(l, r);
  }
  int root = 0;
  while (p[root] != -1) root = p[root];
  range[root] = make_pair(MINV, MAXV);
  dfs(root);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (m.find(val[i]) == m.end()) ++ans;
  }
  cout << ans << endl;
  return 0;
}
