void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto a=new int[](n);
  foreach(i; 0..n) rd(a[i]), a[i]--;

  int cur=0, cnt=0;
  foreach(_; 0..n+1){
    cur=a[cur];
    cnt++;
    if(cur==1){
      writeln(cnt);
      return;
    }
  }
  writeln(-1);

}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}
