Tree#4173

Tree

1 second
64 megabytes
Very hard

Given: an ordered rooted tree and a list of its modifications. The modifications are the following: cut off node with the given number along with the subtree from its current parent node and add it as a rightmost child node to the other node.

You must determine the modification after which the tree becomes isomorphic to one of the previous trees.

In a rooted ordered tree each non-leaf node has an established order of child nodes. Two trees are considered isomorphic if the following is retained in bijective mapping:

Input

The first line of the input file contains two integers: is the number of nodes in the tree and is the number of modifications (2 \leq N \leq 100000, 1 \leq M \leq 100000). The tree nodes are numbered by integer numbers from to . The root node has the number .

The following lines contain ordered lists of child nodes for the nodes of the initial tree. Each -th list is described by the number K_i of children of the -th node and by the sequence of its child node numbers (0 \leq K_i \leq N-1).

The remaining lines contain the description of the tree modifications. Each modification is defined by two integers S_j and F_j — the number of the node being cut from the parent along with its subtree and the number of the node to which it is added as its rightmost child (2 \leq S_j \leq N, 1 \leq F_j \leq N). It is guaranteed that the node F_j is not a descendant of the node S_j and does not coincide with it.

Output

If all M+1 resulting trees are different, the output file must contain the number . Otherwise it must contain two integers and separated by a space — the numbers of two isomorphic trees (0 \leq A < B \leq M). If there are several pairs of isomorphic trees, the output file must contain the pair with the lowest number .

Trees are numbered in the following way: the initial tree has the number , and -th modification results in -th tree (1 \leq j \leq M).

Examples

Example 1

Loading
Loading

Note

Below are some of the trees for the first test from the given data.