#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g;
int val[100000], p;
bool used[100000];
set<int> st, st2;
void dfs(int v, int mxr, int mnl) {
  used[v] = true;
  if (mxr == -1 && mnl == -1)
    st2.insert(val[v]);
  else if (mxr == -1 && mnl > val[v]) {
    st2.insert(val[v]);
  } else if (mnl == -1 && mxr < val[v]) {
    st2.insert(val[v]);
  } else if (mnl > val[v] && mxr < val[v]) {
    st2.insert(val[v]);
  }
  if (g[v].first != -2 && mnl == -1)
    dfs(g[v].first, mxr, val[v]);
  else if (g[v].first != -2)
    dfs(g[v].first, mxr, min(mnl, val[v]));
  if (g[v].second != -2 && mxr == -1)
    dfs(g[v].second, val[v], mnl);
  else if (g[v].second != -2)
    dfs(g[v].second, max(mxr, val[v]), mnl);
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, v, l, r;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v >> l >> r;
    val[i] = v;
    if (l != -1) used[l - 1] = true;
    if (r != -1) used[r - 1] = true;
    g.push_back({l - 1, r - 1});
  }
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      p = i;
      break;
    }
  }
  dfs(p, -1, -1);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (st2.count(val[i]) == 0);
  }
  cout << ans << endl;
  return 0;
}
