"use strict";

var main = function main(input) {
  var args = input.split('\n');
  var N = parseInt(args[0], 10);
  var a = [];

  for (var i = 1; i <= N; i++) {
    a.push(parseInt(args[i], 10));
  }

  var next = a[0];
  var checked = [];
  checked.push(1);
  var flag = false;
  var count = 0;

  while (checked.indexOf(next) >= 0) {
    count++;
    checked.push(next);
    next = a[next - 1];

    if (next == 2) {
      flag = true;
      break;
    }
  }

  if (flag) {
    console.log(count + 1);
  } else {
    console.log(-1);
  }
};

main(require('fs').readFileSync('/dev/stdin', 'utf-8'));