// Arup Guha
// 4/25/2017
// Solution to 2017 NAIPC Problem D: Heaps from Trees

import java.util.*;
import java.io.*;

public class heapstrees {

	final public static long MULT = 1000000001L;

	public static int n;

	public static node[] tree;

	public static void main(String[] args) throws Exception {

		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(stdin.readLine().trim());
		tree = new node[n];

		// Read in each node.
		for (int i=0; i<n; i++) {
			StringTokenizer tok = new StringTokenizer(stdin.readLine());
			int val = Integer.parseInt(tok.nextToken());
			int par = Integer.parseInt(tok.nextToken());
			tree[i] = new node(val);
			if (i > 0) tree[par-1].kids.add(i);
		}

		// Solve and output the result (in this case, the size of the tree set returned.)
		System.out.println(solveRec(0).size());
	}

	// Returns the max answers for the tree rooted at id for each possible length of heap nodes.
	public static TreeSet<Long> solveRec(int id) {

		// Base case at root.
		if (tree[id].kids.size() == 0) {
			TreeSet<Long> ts = new TreeSet<Long>();
			ts.add(tree[id].key*MULT+id);
			return ts;
		}

		// Store all of the answers here, as well as subtree with best results.
		TreeSet[] subtrees = new TreeSet[tree[id].kids.size()];
		int buildoff = 0;
		for (int i=0; i<tree[id].kids.size(); i++) {
			subtrees[i] = solveRec(tree[id].kids.get(i));
			if (subtrees[i].size() > subtrees[buildoff].size())
				buildoff = i;
		}

		// Now, go through all the other subtrees other than buildoff, and add all these items into buildoff.
		for (int i=0; i<tree[id].kids.size(); i++) {

			// Skip this one.
			if (i == buildoff) continue;

			// Add each item from tree i into tree buildoff.
			for (Long x : (TreeSet<Long>)subtrees[i])
				subtrees[buildoff].add(x);
		}

		// Update for this root.
		Long next = ((TreeSet<Long>)subtrees[buildoff]).higher(tree[id].key*MULT-1);
		if (next != null) subtrees[buildoff].remove(next);
		subtrees[buildoff].add(tree[id].key*MULT+id);

		// This is the tree set that stores all of the answers for this recursive call.
		return subtrees[buildoff];
	}
}

class node {

	public int key;
	public ArrayList<Integer> kids;

	public node(int item) {
		key = item;
		kids = new ArrayList<Integer>();
	}
}