Let *T* be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an integer number written on it. Following algorithm is run on every value from the tree *T*:
 1.  Set pointer to the root of a tree. 1.  Return success if the value in the current vertex is equal to the number you are looking for 1.  Go to the left child of the vertex if the value in the current vertex is greater than the number you are looking for 1.  Go to the right child of the vertex if the value in the current vertex is less than the number you are looking for 1.  Return fail if you try to go to the vertex that doesn't exist 
Here is the pseudo-code of the described algorithm: 

The described algorithm works correctly if the tree is binary search tree (i.e. for each node the values of left subtree are less than the value in the node, the values of right subtree are greater than the value in the node). But it can return invalid result if tree is not a binary search tree.

Since the given tree is not necessarily a binary search tree, not all numbers can be found this way. Your task is to calculate, how many times the search will fail being running on every value from the tree.

If the tree has multiple vertices with the same values on them then you should run algorithm on every one of them separately.
First line contains integer number *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>) — number of vertices in the tree.

Each of the next *n* lines contains 3 numbers *v*, *l*, *r* (0 ≤ *v* ≤ 10<sup class="upper-index">9</sup>) — value on current vertex, index of the left child of the vertex and index of the right child of the vertex, respectively. If some child doesn't exist then number  - 1 is set instead. Note that different vertices of the tree may contain the same values.
In the example the root of the tree in vertex 2. Search of numbers 5 and 15 will return fail because on the first step algorithm will choose the subtree which doesn't contain numbers you are looking for.
3
15 -1 -1
10 1 3
5 -1 -1
2
8
6 2 3
3 4 5
12 6 7
1 -1 8
4 -1 -1
5 -1 -1
14 -1 -1
2 -1 -1
1
1
493041212 -1 -1
0
10
921294733 5 9
341281094 -1 -1
35060484 10 -1
363363160 -1 -1
771156014 6 8
140806462 -1 -1
118732846 4 2
603229555 -1 -1
359289513 3 7
423237010 -1 -1
7
10
911605217 -1 -1
801852416 -1 -1
140035920 -1 9
981454947 10 2
404988051 6 3
307545107 8 7
278188888 4 1
523010786 -1 -1
441817740 -1 -1
789680429 -1 -1
7
10
921072710 6 8
727122964 -1 -1
248695736 2 -1
947477665 -1 -1
41229309 -1 -1
422047611 3 9
424558429 -1 4
665046372 -1 5
74510531 -1 -1
630373520 7 1
7
1
815121916 -1 -1
0
1
901418150 -1 -1
0
3
2 -1 -1
1 1 3
2 -1 -1
0
4
20 2 3
16 4 -1
20 -1 -1
20 -1 -1
0
3
2 2 3
1 -1 -1
1 -1 -1
0
4
7122 2 3
87 4 -1
7122 -1 -1
7122 -1 -1
0
4
712222 2 3
98887 4 -1
712222 -1 -1
712222 -1 -1
0
3
6 2 3
5 -1 -1
5 -1 -1
0
4
1 -1 2
0 3 -1
100 -1 4
1 -1 -1
2
4
98 2 3
95 4 -1
98 -1 -1
98 -1 -1
0
3
15 2 3
1 -1 -1
1 -1 -1
0
4
6 2 -1
6 3 4
6 -1 -1
7 -1 -1
1
3
2 2 3
3 -1 -1
3 -1 -1
0
4
1 -1 2
0 3 -1
1 -1 4
0 -1 -1
2
4
1 2 3
2 -1 -1
3 4 -1
2 -1 -1
0
1
0 -1 -1
0
3
5 2 -1
6 -1 3
5 -1 -1
1
10
2 -1 -1
1 -1 8
2 4 9
5 -1 2
5 7 6
1 -1 1
4 -1 -1
0 -1 -1
8 5 10
5 -1 -1
3
8
6 -1 -1
0 5 -1
4 6 7
3 -1 -1
4 3 1
1 -1 -1
2 8 4
2 -1 -1
7
4
5 3 -1
1 4 -1
3 -1 2
1 -1 -1
2
3
10 2 3
5 -1 -1
5 -1 -1
0
# Problem: D. Broken BST
# Contest: Codeforces - Educational Codeforces Round 19
# URL: https://codeforces.com/contest/797/problem/D
# Memory Limit: 256 MB
# Time Limit: 1000 ms

import sys
import bisect
import random
import io, os
from bisect import *
from collections import *
from contextlib import redirect_stdout
from itertools import *
from array import *
from functools import lru_cache
from types import GeneratorType
from heapq import *
from math import sqrt, gcd, inf

if sys.version >= '3.8':  # ACW没有comb
    from math import comb

RI = lambda: map(int, sys.stdin.buffer.readline().split())
RS = lambda: map(bytes.decode, sys.stdin.buffer.readline().strip().split())
RILST = lambda: list(RI())
DEBUG = lambda *x: sys.stderr.write(f'{str(x)}\n')

MOD = 10 ** 9 + 7
PROBLEM = """https://codeforces.com/contest/797/problem/D

输入 n(1≤n≤1e5) 和一棵二叉树的 n 个节点，每行输入 x l r，对应节点值 [0,1e9] 和左右儿子的编号 [1,n]，如果没有则为 -1。
输入保证恰好有一个节点没有父节点，即根节点。

如下是一个在二叉搜索树中查找元素的伪代码：
bool find(TreeNode t, int x) {
    if (t == null)
        return false;
    if (t.value == x)
        return true;
    if (x < t.value)
        return find(t.left, x);
    else
        return find(t.right, x);
}
find(root, x);

把二叉树的每个节点值应用上述代码，输出你会得到多少次 false。
注意节点值可能有重复的。
输入
3
15 -1 -1
10 1 3
5 -1 -1
输出 2
解释 5 和 15 是找不到的
"""
"""https://codeforces.com/contest/797/submission/190439455

考虑有多少个节点值可以找到。
参考 https://www.bilibili.com/video/BV14G411P7C1/ 的方法一，把合法查询范围作为递归参数传下去。
如果节点值 x 在范围内，则有 cnt[x] 个 x 可以找到。

注：用 cnt 是因为有重复的节点，这些节点值都可以找到（即使某些节点无法访问到）。
"""


def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to

    return wrappedfunc


#       ms
def solve():
    n, = RI()
    a = []
    has_fa = [False] * n
    cnt = Counter()
    for i in range(n):
        v, l, r = RI()
        l -= 1
        r -= 1
        cnt[v] += 1
        a.append((v, l, r))
        if l >= 0:
            has_fa[l] = True
        if r >= 0:
            has_fa[r] = True
    root = 0
    while has_fa[root]:
        root += 1
    ans = n
    q = deque([(root, 0, 10 ** 9)])
    while q:
        i, l, r = q.popleft()
        v, x, y = a[i]
        if l <= v <= r:
            ans -= cnt[v]
        if l < v and x >= 0:
            q.append((x, l, min(r, v - 1)))
        if r > v and y >= 0:
            q.append((y, max(l, v + 1), r))
    print(ans)


if __name__ == '__main__':
    solve()
