from collections import * N = int(input()) R = list(map(int, input().split())) G = [[] for i in range(N)] for i in range(1, N): G[i].append((i - 1, 0)) for i in range(N-1): G[i].append((R[i]-1, 1)) Q = deque() Q.append(0) inf = 10 ** 18 dist = [inf] * N dist[0] = 0 while Q: u = Q.popleft() for v, c in G[u]: if dist[v] <= dist[u] + c: continue dist[v] = dist[u] + c if c: Q.append(v) else: Q.appendleft(v) print(dist[-1])