N = int(input()) R = [int(x)-1 for x in input().split()] now =0 for i in range(1,N+1): now = R[now] if now == N-1: print(i) exit()