#include <bits/stdc++.h>
using namespace std;
const int LEN = 100100;
const int INF = 1e9 + 7;
int n, root, res;
int val[LEN], left_son[LEN], right_son[LEN], is_root[LEN];
unordered_map<int, bool> is_found;
void dfs(int v, int l, int r) {
  if (l <= val[v] && val[v] <= r) {
    is_found[val[v]] = 1;
  }
  if (left_son[v] >= 0) {
    dfs(left_son[v], l, min(val[v] - 1, r));
  }
  if (right_son[v] >= 0) {
    dfs(right_son[v], max(val[v] + 1, l), r);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> val[i] >> left_son[i] >> right_son[i];
    --left_son[i];
    --right_son[i];
    if (left_son[i] >= 0) {
      ++is_root[left_son[i]];
    }
    if (right_son[i] >= 0) {
      ++is_root[right_son[i]];
    }
  }
  for (int i = 0; i < n; ++i) {
    if (is_root[i] == 0) {
      root = i;
    }
  }
  dfs(root, -INF, INF);
  for (int i = 0; i < n; ++i) {
    if (is_found.find(val[i]) == is_found.end()) {
      ++res;
    }
  }
  cout << res;
  return 0;
}
