Problem: Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before.
As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree.
A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a node is the last different from vertex on the path from the root to the vertex . Children of vertex are all nodes for which is the parent. A vertex is a leaf if it has no children.
The rooted tree Serval owns has nodes, node is the root. Serval will write some numbers into all nodes of the tree. However, there are some restrictions. Each of the nodes except leaves has an operation or written in it, indicating that the number in this node should be equal to the maximum or minimum of all the numbers in its sons, respectively.
Assume that there are leaves in the tree. Serval wants to put integers to the leaves (each number should be used exactly once). He loves large numbers, so he wants to maximize the number in the root. As his best friend, can you help him?
Input Format: The first line contains an integer (), the size of the tree.
The second line contains integers, the -th of them represents the operation in the node . represents and represents . If the node is a leaf, there is still a number of or , but you can ignore it.
The third line contains integers (), where represents the parent of the node .
Output Format: Output one integer — the maximum possible number in the root of the tree.
Note: Pictures below explain the examples. The numbers written in the middle of the nodes are their indices, and the numbers written on the top are the numbers written in the nodes.
In the first example, no matter how you arrange the numbers, the answer is .
In the second example, no matter how you arrange the numbers, the answer is .
In the third example, one of the best solution to achieve is to arrange and to nodes and .
In the fourth example, the best solution is to arrange to node .