## https://yukicoder.me/problems/no/1868 import heapq MAX_INT = 10 ** 18 def main(): N = int(input()) R = list(map(int, input().split())) dp = [MAX_INT] * N queue = [] heapq.heappush(queue,(0, 0)) for x in range(N): while len(queue) > 0 and queue[0][-1] < x: heapq.heappop(queue) v = queue[0][0] dp[x] = v if x < N - 1: heapq.heappush(queue, (v + 1, R[x] - 1)) print(dp[-1]) if __name__ == "__main__": main()