a, b, c = gets.split.map &:to_i
x = 0
hash = {x => 0}
t = 0

loop {
    if (c + x) % (a + b) <= a
        puts 60 * t + c
        break
    end

    x = (x + 60) % (a + b)
    if hash[x]
        puts -1
        break
    end
    hash[x] = 0

    t += 1
}