from collections import deque N = int(input()) A = list(map(int, input().split())) d = deque() seen = [False]*N dis = [-1]*N dis[0] = 0 d.append(0) while d: v = d.popleft() if v == N-1: break for i in range(v+1, A[v]): if not seen[i]: dis[i] = dis[v]+1 seen[i] = True d.append(i) print(dis[-1])