local read = io.read
local n = read("n")
local a = {}
for i = 1, n do
	a[i] = read("n")
end

local has_shined = {}
local function push_switch(light_num, push_times)
	if light_num == 2 then
		return push_times
	elseif has_shined[light_num] then
		return -1
	else
		has_shined[light_num] = true
		push_times = push_times + 1
		return push_switch(a[light_num], push_times)
	end
end

print(push_switch(1, 0))
