'use strict'

function main(s) {

  s = s.split('\n');
  const N = Number(s[0]);
  const buttons = s.slice(1, -1).map(n => Number(n));

  let ans = -1;

  for (var i = 1, j = 0; i <= N; i++) {
    j = buttons[j] - 1;

    if (j === 1) {
      ans = i;
      break;
    }
  }

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
