#include <bits/stdc++.h>
using namespace std;
template <typename TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << " = " << h << "\n";
}
template <typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << " = " << h << ",";
  _dbg(sdbg + 1, t...);
}
const int N = 1e5 + 5, INF = 1e9;
int n, a[N], l[N], r[N];
int degIn[N];
map<int, bool> mark;
void DFS(int u, int minLeft, int maxRight) {
  if (minLeft > a[u] && maxRight < a[u]) {
    mark[a[u]] = true;
  }
  if (~l[u]) {
    DFS(l[u], min(minLeft, a[u]), maxRight);
  }
  if (~r[u]) {
    DFS(r[u], minLeft, max(maxRight, a[u]));
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> l[i] >> r[i];
    if (~l[i]) {
      degIn[l[i]]++;
    }
    if (~r[i]) {
      degIn[r[i]]++;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (degIn[i] == 0) {
      DFS(i, INF, -INF);
      break;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (!mark.count(a[i])) {
      ans++;
    }
  }
  cout << ans;
  return 0;
}
