#include<iostream>
using namespace std;
int n,cnt,a[100005],j,f,i,k;
int main(){
    cin>>n;
    for(k=0;k<n;k++)cin>>a[k];
    for(;cnt<=n;){
        f=a[i];
        if(a[i]==2){j=1;break;}
        i=f-1,cnt++;
    }
    cout<<(j?cnt+1:-1)<<endl;
}