process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});
process.stdin.on('end', function() {
    main(g_input.split(/\r?\n/));
});

function main(inputs) {
  var N = inputs[0];
  var count = 1;
  var next = 1;
  for(; count <= N; count++){
    if(next == -1){
      console.log(-1);
      return;
    }
    var temp  = inputs[next];
    inputs[next] = -1;
    next = temp;
    if(next == 2){
      console.log(count);
      return;
    }
  }
}
