#include <bits/stdc++.h>
using namespace std;
int val[100100], root[100100];
vector<pair<int, char> > adj[100100];
set<int> st;
void dfs(int x, int mx, int mn, int par);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, i, j, k, l, v, r;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> v >> l >> r;
    val[i] = v;
    if (l != -1) {
      adj[i].push_back(make_pair(l, 'l'));
      adj[l].push_back(make_pair(i, 'p'));
      root[l] = 1;
    }
    if (r != -1) {
      adj[i].push_back(make_pair(r, 'r'));
      adj[r].push_back(make_pair(i, 'p'));
      root[r] = 1;
    }
  }
  int rt = -1;
  for (i = 1; i <= n; i++)
    if (!root[i]) rt = i;
  int mx = -1, mn = 2e9;
  dfs(rt, mx, mn, -1);
  int ans = 0;
  for (i = 1; i <= n; i++) {
    if (st.find(val[i]) == st.end()) ans++;
  }
  cout << ans << endl;
}
void dfs(int x, int mx, int mn, int par) {
  if (mx < val[x] && mn > val[x]) st.insert(val[x]);
  for (auto next : adj[x]) {
    if (next.first != par) {
      if (next.second == 'l')
        dfs(next.first, mx, min(mn, val[x]), x);
      else if (next.second == 'r')
        dfs(next.first, max(mx, val[x]), mn, x);
    }
  }
}
