fun main(args: Array<String>?): Unit {
    val (a, b ,c) = readLine()!!.trim().split(' ').map(String::toInt)
    for (t in 0 until 60){
        if ((60 * t + c) % (a + b) <= a) {
            println(60 * t + c)
            return
        }
    }
    println(-1)
}

