console.log((args=>{
  let [N,...a] = args.trim().split`\n`.map(v=>v-1);
  let c = a[0];
  for ( let i = 1; i <= N; i++ ) {
    if ( c === 1 ) return i;
    c = a[c];
  }
  return '-1';
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
