#include <bits/stdc++.h>
using namespace std;
struct _ {
  ios_base::Init i;
  _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
} _;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);
  vector<int> in_deg(n + 1, 0);
  vector<vector<int>> gr(n + 1, vector<int>(2, -1));
  set<int> ss;
  for (int i = 1; i <= n; i++) {
    int v, l, r;
    cin >> v >> l >> r;
    a[i] = v;
    if (l != -1) gr[i][0] = l, in_deg[l]++;
    if (r != -1) gr[i][1] = r, in_deg[r]++;
  }
  int root = 1;
  for (; root <= n and in_deg[root] != 0; root++)
    ;
  set<int> s;
  function<void(int, int, int)> dfs = [&](int curr, int minx,
                                          int maxx) -> void {
    if (minx >= maxx) return;
    if (minx < a[curr] and a[curr] < maxx) s.insert(a[curr]);
    if (gr[curr][0] != -1) dfs(gr[curr][0], minx, min(maxx, a[curr]));
    if (gr[curr][1] != -1) dfs(gr[curr][1], max(minx, a[curr]), maxx);
  };
  dfs(root, INT_MIN, INT_MAX);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (s.find(a[i]) == s.end()) ans++;
  cout << ans;
  return 0;
}
