n,q=map(int,input().split()) a=list(map(int,input().split()))+[10**10] e=[] s=[-1] for i in range(n): while a[s[-1]]