#include<bits/stdc++.h>
using namespace std;

int main(){
  int N;
  cin >>N;
  int a[N];
  for (int i=0;i<N;i++){
    cin >> a[i];
  }
  
  int temp=0;
  
  for (int i=0;i<N;i++){
    temp=a[temp]-1;
    if (temp==1){
      cout<<i+1<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}
