import sys input = sys.stdin.readline N = int(input()) a = list(map(int, input().split())) e = [[] for _ in range(N)] for x in range(N - 1): e[x + 1].append((x, 0)) for i in range(N - 1): e[i].append((a[i] - 1, 1)) from collections import deque as dq Q = dq([0]) dp = [N + 1] * N dp[0] = 0 while len(Q): x = Q.popleft() for y, c in e[x]: if dp[y] > dp[x] + c: dp[y] = dp[x] + c if c: Q.append(y) else: Q.appendleft(y) print(dp[-1])