#include <cstdio>
int n, c, a[100005];
int main() {
	int i, j;
	scanf("%d", &n);
	for(i=1; i<=n; i++) scanf("%d", &a[i]);
	for(i=1; i!=2 && a[i]>0; ) {
		c++;
		j = a[i];
		a[i] = 0;
		i = j;
	}
	printf("%d", i==2 ? c:-1);
	return 0;
}