print((function (f, n) local r=f() if r<=0 then return -1 end for i=2,n do r=f(r) if r<=0 then return -1 end end return r end)(function (n) local t = -io.stdin:read("*n")+io.stdin:read("*n") if n == nil then n = t end return n == t and n or -1 end, tonumber(io.stdin:read("*l"))))