n = int(input()) r = list(map(int,input().split())) now = 1 ans = 0 while now != n: now = r[now-1] ans += 1 print(ans)