import Control.Applicative
inputs = fmap (read :: String -> Int) . words <$> getLine

term a b = [((a+b)*n, (a+b)*n + a) | n <- [0..60]]
cs c = [c + n*60 | n<-[0..60]]
solve lst = if null ans then -1 else head ans
    where
        a = lst !! 0
        b = lst !! 1
        c = lst !! 2
        ncs = cs c
        ts  = term a b
        ans = [nc | t<-ts, nc <- ncs, fst t <= nc, nc <= snd t]


main = inputs >>= \l -> print $ solve l