#!/usr/local/gnu/bin/bash
read n
a=()
passed=()
for i in `seq $n`
do
    read x
    a[$i]=$x
    passed[$i]=0
done
i=1
cnt=0
while((i!=2&&passed[i]==0))
do
    passed[$i]=1
    i=${a[i]}
    cnt=$((cnt+1))
done
((i==2)) && echo $cnt || echo -1
