#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& num) {
  num = 0;
  bool f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = 0;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    num = num * 10 + ch - '0';
    ch = getchar();
  }
  num = f ? num : -num;
}
template <class T>
inline void write(T x, char ch) {
  int s[100];
  if (x == 0) {
    putchar('0');
    putchar(ch);
    return;
  }
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  int num = 0;
  while (x) {
    s[num++] = (x % 10);
    x = x / 10;
  }
  for (int i = (num - 1); i >= (0); i--) putchar(s[i] + '0');
  putchar(ch);
}
const double pi = acos(-1);
const double eps = 1e-8;
int ch[100005][2], v[100005], sz[100005], fa[100005];
int n, sum;
set<int> s;
map<int, int> h;
void DFS(int x) {
  sz[x] = 1;
  if (ch[x][0] && ch[x][0] != -1) {
    DFS(ch[x][0]);
    sz[x] += sz[ch[x][0]];
  }
  if (ch[x][1] && ch[x][1] != -1) {
    DFS(ch[x][1]);
    sz[x] += sz[ch[x][1]];
  }
}
void dfs(int x, int up, int down) {
  if (v[x] < down || v[x] > up)
    sum++;
  else
    s.insert(v[x]);
  if (ch[x][0] && ch[x][0] != -1) dfs(ch[x][0], min(v[x], up), down);
  if (ch[x][1] && ch[x][1] != -1) dfs(ch[x][1], up, max(v[x], down));
}
int main() {
  read(n);
  for (int i = (1); i <= (n); i++) {
    read(v[i]);
    if (!h.count(v[i]))
      h[v[i]] = 1;
    else
      h[v[i]] = h[v[i]] + 1;
    int l, r;
    read(l);
    read(r);
    if (l != -1) ch[i][0] = l, fa[l] = i;
    if (r != -1) ch[i][1] = r, fa[r] = i;
  }
  int root;
  for (int i = (1); i <= (n); i++)
    if (fa[i] == 0) root = i;
  DFS(root);
  dfs(root, 1070000000, -1070000000);
  sum = 0;
  for (set<int>::iterator it = s.begin(); it != s.end(); it++) sum += h[*it];
  write(n - sum, '\n');
}
