N = int(input()) R = list(map(int, input().split())) now = 1 c = 0 while now != N: now = R[now-1] c += 1 print(c)