#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,cnt=0,p=1,tmp;
  cin >> N;
  vector<int> A(N+1);
  for(int i=1;i<=N;i++){
    cin >> A[i];
  }
  while(1){
    if(A[p]==-1 || A[p]==2) break;
    tmp=p;
    p=A[p];
    A[tmp]=-1;
    cnt++;
  }
  cout << (A[p]==-1?-1:cnt+1) << endl;
}