N = int(input()) R = list(map(int, input().split())) dp = [float('inf')] * (N) dp[0] = 0 for s, g in enumerate(R): dp[g-1] = min(dp[g-1], dp[s] + 1) print (dp[N-1])