import heapq INF = 1 << 60 n = int(input()) r = list(map(int, input().split())) g = [[] for _ in range(n)] for u in range(n - 1): g[u].append((r[u] - 1, 1)) for u in range(n - 1): g[u + 1].append((u, 0)) src = 0 dist = [INF for _ in range(n)] dist[src] = 0 hp = [(0, src)] while len(hp) > 0: cd, cur = heapq.heappop(hp) if cd > dist[cur]: continue for nxt, cost in g[cur]: if dist[nxt] > dist[cur] + cost: dist[nxt] = dist[cur] + cost heapq.heappush(hp, (dist[nxt], nxt)) print(dist[-1])