N = int(input()) A = list(map(int, input().split())) ans = 0 now = 0 while now < N - 1: now = A[now] - 1 ans += 1 print(ans)