You are playing a game consisting of n planets. Each planet has a teleporter to another planet (or the planet itself).
Your task is to process q queries of the form: when you begin on planet x and travel through k teleporters, which planet will you reach?
The first line has two integers n and q(1≤n,q≤2⋅105): the number of planets and queries. The planets are numbered 1,2,…,n.
The second line has n integers t1,t2,…,tn(1≤ti≤n): for each planet, the destination of the teleporter. It is possible that ti=i.
Finally, there are q lines describing the queries. Each line has two integers x(1≤x≤n) and k(0≤k≤109): you start on planet x and travel through k teleporters.
Print the answer to each query.