INF = 10 ** 18 n = int(input()) r = list(map(int,input().split())) dp = [INF] * (n + 1) dp[n - 1] = 0 for i in range(n - 2, -1, -1): dp[i] = min(dp[i], dp[i + 1] + 1, dp[r[i] - 1] + 1) print(dp[0])