#include <bits/stdc++.h>
using namespace std;
int t = 1;
const int N = 100005, inf = (int)1000000007;
vector<int> val(N), lft(N), rgt(N);
set<int> seta;
void dfs(int node, int a, int b) {
  if (a <= val[node] and val[node] <= b) seta.insert(val[node]);
  if (lft[node] != -1) dfs(lft[node], a, min(val[node] - 1, b));
  if (rgt[node] != -1) dfs(rgt[node], max(val[node] + 1, a), b);
}
void solve() {
  int n, ans = 0, root;
  cin >> n;
  for (int i = 1; i < n + 1; i += 1) {
    cin >> val[i] >> lft[i] >> rgt[i];
    seta.insert(lft[i]);
    seta.insert(rgt[i]);
  }
  for (int i = 1; i < n + 1; i += 1)
    if (seta.find(i) == seta.end()) root = i;
  seta.clear();
  dfs(root, -inf, inf);
  for (int i = 1; i < n + 1; i += 1)
    if (seta.find(val[i]) == seta.end()) ans++;
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  while (t--) {
    solve();
  }
  return 0;
}
