#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const long long MOD = 1000000007ll;
const long double PI = acos(-1.0);
const long long INF = 2000000000000000000ll;
const long double EPS = 1e-9;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T lcm(T a, T b) {
  return a * (b / gcd(a, b));
}
template <typename T>
T sqr(T a) {
  return a * a;
}
bool pal(string &x) {
  int n = x.length();
  for (int i = 0; i < n / 2; i++) {
    if (x[i] != x[n - i - 1]) return 0;
  }
  return 1;
}
bool root[111111];
int l[111111], r[111111];
int val[111111];
bool used[111111];
set<int> valids;
set<int> S;
void DFS(int i, int askdfa, int akfldsa) {
  if (i == -1) {
    return;
  }
  if (askdfa <= val[i] && val[i] <= akfldsa) valids.insert(val[i]);
  DFS(l[i], askdfa, min(akfldsa, val[i] - 1));
  DFS(r[i], max(askdfa, val[i] + 1), akfldsa);
}
void solve() {
  int n;
  cin >> n;
  int a, b, c;
  for (int i = 1; i < n + 1; i++) {
    cin >> a >> b >> c;
    val[i] = a;
    l[i] = b;
    r[i] = c;
    if (b != -1) root[b] = true;
    if (c != -1) root[c] = true;
  }
  int Root = -1;
  for (int i = 1; i < n + 1; i++)
    if (!root[i]) Root = i;
  DFS(Root, 0, inf);
  int answer = n;
  for (int i = 1; i < n + 1; i++) {
    if (valids.count(val[i])) answer--;
  }
  cout << answer;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
