#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long long int mod = 1e9 + 7;
const long long int MXM = 1e5 + 6;
vector<pair<long long int, long long int>> g(MXM);
map<long long int, long long int> vis, frq;
long long int val[MXM];
long long int sol = 0;
void dfs(long long int n, long long int low, long long int high) {
  if (n == -1) return;
  long long int l, r;
  l = g[n].first;
  r = g[n].second;
  if (val[n] > low && val[n] < high) {
    sol += frq[val[n]];
    frq[val[n]] = 0;
  }
  if (l != -1) dfs(l, low, min(val[n], high));
  if (r != -1) dfs(r, max(low, val[n]), high);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t, n, i, j, k, len, x, y, z, c, f, flag, p, q, mx, mn, l, r,
      sum, ans, tmp, it, pos, avg, m, cnt;
  string s;
  char ch;
  vector<long long int> v;
  vector<pair<long long int, long long int>> vec;
  unordered_map<long long int, long long int> mappu;
  pair<long long int, long long int> pr;
  t = 1;
  {
    f = 0;
    sum = 0;
    flag = 0;
    ans = 0;
    cnt = 0;
    v.clear();
    mappu.clear();
    vec.clear();
    cin >> n;
    for (i = 1; i <= n; i++) {
      cin >> val[i] >> g[i].first >> g[i].second;
      vis[g[i].first] = 1;
      vis[g[i].second] = 1;
      frq[val[i]]++;
    }
    long long int root = -1;
    for (i = 1; i <= n; i++) {
      if (vis[i] == 0) {
        root = i;
        break;
      }
    }
    dfs(root, -1, 1e10);
    sol = n - sol;
    cout << sol << "\n";
  }
  return 0;
}
