Äventyr 2

On a tree, timelines get marked over time, and after each mark you must report the distance from a queried vertex to the nearest marked vertex.

Hard8TreeBFSPrefix sumDFSNo attempts yetTime limit1sMemory limit256 MB

Problem

"Äventyr bortom tidpunkten, Sista Fiolen."

You travel between timelines to find the legendary violin of a forgotten country. Each timeline is a vertex of a tree, and an edge of the tree means you can move between the two timelines it joins. The timelines are numbered from 11 to NN. Some timelines hold the legendary violin and the rest do not. At the start, no timeline holds the violin. After the tree is given, process QQ queries of the following two kinds.

  • 1 u: timeline uu becomes a timeline that holds the violin.
  • 2 u: print the minimum number of edges a journey starting at timeline uu must cross to reach a timeline that holds the violin. If no timeline holds the violin, print 1-1.

Input

The first line contains NN and QQ. (1N,Q1051 \le N, Q \le 10^5)

The second line contains N1N-1 integers A2,A3,,ANA_2, A_3, \ldots, A_N. AiA_i means that the parent of timeline ii in the tree is timeline AiA_i. (1AiN1 \le A_i \le N, AiiA_i \ne i) The given edges always form a single tree. When N=1N = 1, the second line is empty.

Each of the next QQ lines contains one query in the form c v. If c=1c = 1 it is a query of type 1, and if c=2c = 2 it is a query of type 2. (1vN1 \le v \le N) A query of type 1 is never given twice for the same timeline.

Output

For every query of type 2, print its result on its own line, in order.