#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits<int>::max();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> val(n);
  vector<pair<int, int> > g(n);
  for (int i = 0, v, l, r; i < n; i++) {
    cin >> v >> l >> r;
    val[i] = v;
    g[i] = {l - 1, r - 1};
  }
  set<int> works;
  function<void(int, int, int)> dfs = [&](int u, int l, int r) {
    if (u == -2) return;
    if (l > val[u] and r < val[u]) works.insert(val[u]);
    dfs(g[u].first, min(l, val[u]), r);
    dfs(g[u].second, l, max(val[u], r));
  };
  vector<bool> is_root(n, true);
  for (auto &x : g) {
    if (x.first != -2) is_root[x.first] = false;
    if (x.second != -2) is_root[x.second] = false;
  }
  for (int i = 0; i < n; i++) {
    if (is_root[i]) {
      dfs(i, INF, -INF);
      break;
    }
  }
  int ans = 0;
  for (auto &x : val) ans += (!works.count(x));
  cout << ans << endl;
}
