import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] rs = new int[n-1]; for(int i = 0 ; i < n - 1 ; i++){ rs[i] = sc.nextInt(); } int now = rs[0]; int ans = 1; while(now != n){ now = rs[now-1]; ans++; } System.out.println(ans); } }