#include <bits/stdc++.h>
long long int pow(long long int a, long long int b, long long int m) {
  long long int x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y);
      if (x > m) x %= m;
    }
    y = (y * y);
    if (y > m) y %= m;
    b /= 2;
  }
  return x % m;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long int gen(long long int start, long long int end) {
  long long int diff = end - start;
  long long int temp = rand() % start;
  return temp + diff;
}
using namespace std;
long long int v[100001];
long long int l[100001];
long long int r[100001];
long long int lb[100001];
set<int> ss;
long long int ub[100001];
long long int ans = 0;
set<int> s;
void dfs(int node) {
  if (lb[node] > ub[node] || v[node] > ub[node] || v[node] < lb[node]) {
  } else {
    ss.insert(v[node]);
  }
  if (l[node] != -1) {
    lb[l[node]] = lb[node];
    ub[l[node]] = min(ub[node], v[node]);
    dfs(l[node]);
  }
  if (r[node] != -1) {
    lb[r[node]] = max(lb[node], v[node]);
    ub[r[node]] = ub[node];
    dfs(r[node]);
  }
}
set<int> cc;
map<int, int> mmm;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i] >> l[i] >> r[i];
    s.insert(l[i]);
    s.insert(r[i]);
    cc.insert(v[i]);
    mmm[v[i]]++;
  }
  int root;
  for (int i = 1; i <= n; i++) {
    if (s.find(i) == s.end()) {
      root = i;
      break;
    }
  }
  int ans = 0;
  lb[root] = -10000000001;
  ub[root] = +10000000001;
  dfs(root);
  for (int i : cc) {
    if (ss.find(i) == ss.end()) ans += mmm[i];
  }
  cout << ans;
}
