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