#include <bits/stdc++.h>
using namespace std;
struct node {
  int key = -1;
  int left = 0;
  int right = 0;
  int prev = 0;
};
vector<node> v;
stack<int> tmin, tmax;
set<int> data;
void InOrder(int u) {
  if (u != -1) {
    bool flag = 0;
    if (v[u].key < tmin.top()) {
      flag = 1;
      tmin.push(v[u].key);
    }
    InOrder(v[u].left);
    if (flag) {
      tmin.pop();
    }
    if (v[u].key < tmin.top() && v[u].key > tmax.top()) {
      data.insert(v[u].key);
    }
    flag = 0;
    if (v[u].key > tmax.top()) {
      flag = 1;
      tmax.push(v[u].key);
    }
    InOrder(v[u].right);
    if (flag) {
      tmax.pop();
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<bool> used(n + 1);
  v.resize(n + 1);
  vector<int> tmp;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].key >> v[i].left >> v[i].right;
    tmp.push_back(v[i].key);
    if (v[i].left != -1) {
      v[v[i].left].prev = i;
      used[v[i].left] = 1;
    }
    if (v[i].right != -1) {
      v[v[i].right].prev = i;
      used[v[i].right] = 1;
    }
  }
  int root = 0;
  for (int i = 1; i <= n; i++) {
    if (used[i] == 0) {
      root = i;
    }
  }
  tmin.push(1000 * 1000 * 1000 + 1);
  tmax.push(-1);
  InOrder(root);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (data.count(tmp[i]) == 0) {
      cnt++;
    }
  }
  cout << cnt << endl;
}
