#include <bits/stdc++.h>
using namespace std;
struct triple {
  int a, b, c;
};
triple make(int a, int b, int c) {
  triple blank;
  blank.a = a;
  blank.b = b;
  blank.c = c;
  return blank;
}
int main() {
  int n;
  cin >> n;
  int tree[n][3];
  vector<bool> parent(n, false);
  for (int i = 0; i < n; i++) {
    cin >> tree[i][0] >> tree[i][1] >> tree[i][2];
    tree[i][1]--;
    tree[i][2]--;
    if (tree[i][1] >= 0) {
      parent[tree[i][1]] = true;
    }
    if (tree[i][2] >= 0) {
      parent[tree[i][2]] = true;
    }
  }
  int root = -15;
  for (int i = 0; i < n; i++) {
    if (not parent[i]) {
      root = i;
    }
  }
  stack<triple> dfs;
  dfs.push(make(root, -1, 1000000001));
  int total = 0;
  map<int, pair<int, bool> > done;
  while (dfs.size() > 0) {
    triple current = dfs.top();
    dfs.pop();
    if (tree[current.a][0] < current.b or tree[current.a][0] > current.c) {
      if (done.find(tree[current.a][0]) == done.end()) {
        done[tree[current.a][0]] = make_pair(1, false);
        total++;
      } else if (done[tree[current.a][0]].second == false) {
        done[tree[current.a][0]].first++;
        total++;
      }
    } else {
      if (done.find(tree[current.a][0]) == done.end()) {
        done[tree[current.a][0]] = make_pair(1, true);
      } else if (done[tree[current.a][0]].second == false) {
        total -= done[tree[current.a][0]].first;
        done[tree[current.a][0]].second = true;
      }
    }
    if (tree[current.a][1] >= 0) {
      dfs.push(make(tree[current.a][1], current.b,
                    min(current.c, tree[current.a][0])));
    }
    if (tree[current.a][2] >= 0) {
      dfs.push(make(tree[current.a][2], max(current.b, tree[current.a][0]),
                    current.c));
    }
  }
  cout << total;
}
