#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
int f[100005], val[100005], l[100005], r[100005], R;
set<int> ans;
const int MN = 270000;
map<int, int> mp;
int cnt;
struct mb {
  int M, T[MN];
  void init(int sz) {
    for (M = 1; sz + 2 > M; M <<= 1)
      ;
  }
  void clear() { memset(T, 0, sizeof T); }
  int qy(int l) {
    l += M;
    int ans = T[l];
    while (l > 1) {
      ans += T[l >> 1];
      l >>= 1;
    }
    return ans;
  }
  void upt(int l, int r, int val) {
    for (l = l + M - 1, r = r + M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
      if (~l & 1) T[l ^ 1] += val;
      if (r & 1) T[r ^ 1] += val;
    }
  }
} T;
void dfs(int x) {
  if (T.qy(val[x]) == 0) ans.insert(val[x]);
  if (l[x] != -1) {
    T.upt(val[x] + 1, cnt, 1);
    dfs(l[x]);
    T.upt(val[x] + 1, cnt, -1);
  }
  if (r[x] != -1) {
    T.upt(1, val[x] - 1, 1);
    dfs(r[x]);
    T.upt(1, val[x] - 1, -1);
  }
}
void fmain(int tid) {
  scanf("%d", &n);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    scanf("%d%d%d", val + i, l + i, r + i);
    if (l[i] != -1) f[l[i]] = i;
    if (r[i] != -1) f[r[i]] = i;
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (f[i] == 0) {
      R = i;
      break;
    }
  for (int(i) = 1; (i) <= (int)(n); (i)++) mp[val[i]];
  for (auto &p : mp) p.second = ++cnt;
  for (int(i) = 1; (i) <= (int)(n); (i)++) val[i] = mp[val[i]];
  T.init(cnt);
  dfs(R);
  int Ans = 0;
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (ans.find(val[i]) == ans.end()) Ans++;
  printf("%d\n", Ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
