function Main(s) {
  var s = s.split("\n").map(e => e*1);
  var cnt = 0, idx = 1, flag = false;
  for(var i = 1; i <= s[0]; i++) {
    cnt++;
    if (s[idx] === 2) {
      flag = true;
      break;
    } else {
      idx = s[idx];
    }
  }
  console.log(flag ? cnt:-1);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));