{"raw_statement":[{"iden":"problem statement","content":"We have a rooted tree with $N$ vertices numbered $1$ to $N$. Vertex $1$ is the root, and the parent of vertex $i$ is vertex $P_i$.  \nThere are $N$ coins with heads and tails, one on each vertex.  \nAdditionally, there are $N$ buttons numbered $1$ to $N$. Pressing button $n$ flips all coins on the vertices in the subtree rooted at vertex $n$.\nProcess $Q$ queries described below.\nIn the $i$\\-th query, you are given a vertex set of size $M_i$: $S_i = \\lbrace v_{i,1}, v_{i,2},\\dots, v_{i,M_i} \\rbrace$.  \nNow, the coins on the vertices in $S_i$ are facing heads-up, and the others are facing tails-up. In order to make all $N$ coins face tails-up by repeatedly choosing a button and pressing it, at least how many button presses are needed? Print the answer, or $-1$ if there is no way to make all the coins face tails-up."},{"iden":"constraints","content":"*   $2 \\leq N \\leq 2 \\times 10^5$\n*   $1 \\leq P_i \\lt i$\n*   $1 \\leq Q \\leq 2 \\times 10^5$\n*   $1 \\leq M_i$\n*   $\\displaystyle \\sum_{i=1}^Q M_i \\leq 2 \\times 10^5$\n*   $1 \\leq v_{i,j} \\leq N$\n*   $v_{i,1}, v_{i,2},\\dots,v_{i,M_i}$ are pairwise different.\n*   All values in the input are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$ $Q$\n$P_2$ $P_3$ $\\dots$ $P_N$\n$M_1$ $v_{1,1}$ $v_{1,2}$ $\\dots$ $v_{1,M_1}$\n$M_2$ $v_{2,1}$ $v_{2,2}$ $\\dots$ $v_{2,M_2}$\n$\\vdots$\n$M_Q$ $v_{Q,1}$ $v_{Q,2}$ $\\dots$ $v_{Q,M_Q}$"},{"iden":"sample input 1","content":"6 6\n1 1 2 2 5\n6 1 2 3 4 5 6\n3 2 5 6\n1 3\n3 1 2 3\n3 4 5 6\n4 2 3 4 5"},{"iden":"sample output 1","content":"1\n2\n1\n3\n2\n3\n\nFor the first query, you can satisfy the requirement in one button press, which is the minimum needed, as follows.\n\n*   Press button $1$, flipping the coins on vertices $1,2,3,4,5,6$.\n\nFor the second query, you can satisfy the requirement in two button presses, which is the minimum needed, as follows.\n\n*   Press button $4$, flipping the coin on vertex $4$.\n*   Press button $2$, flipping the coins on vertex $2,4,5,6$."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}