local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local cnt = 0
local cur = 1
while cnt < n do
  cnt = cnt + 1
  cur = a[cur]
  if cur == 2 then break end
end
print(cnt < n and cnt or -1)
