#include <bits/stdc++.h>
using namespace std;
long long powm(long long base, long long exp, long long mod = 1000000007) {
  long long ans = 1;
  while (exp) {
    if (exp & 1) ans = (ans * base) % mod;
    exp >>= 1, base = (base * base) % mod;
  }
  return ans;
}
long long addm(long long a, long long b) {
  long long tmp = a + b;
  if (tmp > 1000000007) tmp -= 1000000007;
  return tmp;
}
vector<bool> visited(100005);
vector<long long> a(100005);
vector<vector<long long> > c(100005, vector<long long>(2, 0));
map<long long, long long> cnt;
vector<bool> cant(100005);
set<long long> s;
void dfs(long long idx, long long child, long long mn, long long mx) {
  if (mn + 1 >= mx) {
    return;
  }
  if (a[idx] > mn && a[idx] < mx) {
    s.insert(a[idx]);
    if (c[idx][0] != -1) {
      if (a[c[idx][0]] < a[idx]) {
        if (a[idx] < mx)
          dfs(c[idx][0], 0, mn, a[idx]);
        else
          dfs(c[idx][0], 0, mn, mx);
      } else {
        dfs(c[idx][0], 0, mn, a[idx]);
      }
    }
    if (c[idx][1] != -1) {
      if (a[c[idx][1]] > a[idx]) {
        if (a[idx] > mn)
          dfs(c[idx][1], 1, a[idx], mx);
        else
          dfs(c[idx][1], 1, mn, mx);
      } else {
        dfs(c[idx][1], 1, a[idx], mx);
      }
    }
  } else {
    if (child == 0) {
      if (a[idx] >= mx) {
        if (c[idx][0] != -1) {
          dfs(c[idx][0], 0, mn, mx);
        }
      } else if (a[idx] <= mn) {
        if (c[idx][1] != -1) {
          dfs(c[idx][1], 1, mn, mx);
        }
      }
    } else {
      if (a[idx] >= mx) {
        if (c[idx][0] != -1) {
          dfs(c[idx][0], 0, mn, mx);
        }
      } else if (a[idx] <= mn) {
        if (c[idx][1] != -1) {
          dfs(c[idx][1], 1, mn, mx);
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(0) << fixed;
  long long i, j, k, m, n, res = 0, sum = 0, flag = 0, root, par, ppar;
  cin >> n;
  for (long long i = 1; i < n + 1; i++) {
    cin >> a[i] >> c[i][0] >> c[i][1];
    cnt[a[i]]++;
    if (c[i][0] != -1) visited[c[i][0]] = true;
    if (c[i][1] != -1) visited[c[i][1]] = true;
  }
  for (long long i = 1; i < n + 1; i++) {
    if (visited[i] == false) {
      root = i;
      break;
    }
  }
  dfs(root, 0, -1, 1000111000111000111LL);
  for (auto &value : s) {
    res += cnt[value];
  }
  cout << n - res;
  return 0;
}
