Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	a, b, c := io.NextInt(), io.NextInt(), io.NextInt()
	for i := 0; i < 61; i++ {
		for j := 0; j < 61; j++ {
			if (a+b)*i-60*j <= c && c <= (a+b)*i-60*j+a {
				io.Println(60*j + c)
				return
			}
		}
	}
	io.Println(-1)
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

Python: from itertools import count
a,b,c=map(int,raw_input().split())
g=set()
for n in count(0):
    p=(c+60*n)//(a+b)
    print (a+b)*p,c+60*n,(a+b)*p+a
    if ((a+b)*p-(c+60*n),(c+60*n)-((a+b)*p+a)) in g:
        n=-1
        break
    if (a+b)*p<=c+60*n<=(a+b)*p+a:
        break
    else:
        d=(a+b)*p-(c+60*n)
        e=(c+60*n)-((a+b)*p+a)
        g.add((d,e))
if n>=0:
    print(c+60*n)
else:
    print(n)

Python: a,b,c=map(int, input().split())
d,e=0,60
for _ in range(e):
    if c<=d+a:
        print(c)
        break
    d+=a+b
    c+=(d+e-c)//e*e
else: print(-1)

Python: def solve(a, b, c):
    if a == b == 30:
        print(-1)
        exit()

    l = 0; r = a;
    for t in range(114514):
        p = 60*t + c
        if l <= p <= r:
            print(p)
            exit()

        l = r + b
        r = l + a

a, b, c = map(int, input().split())
solve(a,b,c)

Python: A, B, C = map(int, input().split())
t = 0
while True:
    t += A
    if t >= C:
        print(C)
        break
    t += B
    if t > C:
        C += 60
    if t > 1000000:
        print(-1)
        break

Python: a,b,c = map(int, input().split())
if (a+b) % 60 == 0 and c%60 >30:
    ans = -1
else:
    if a >= c:
        ans = c
    else:
        key = (a+b)%60
        i = 2
        while 1:
            if key <= a:
                break
            key *= i
            key = key%60
            i += 1
        ans = (i-1)*60+c
print(ans)

Python: def solve(a, b, c):
    l = 0; r = a;
    for t in range(114514):
        p = 60*t + c
        if l <= p <= r:
            print(p)
            exit()

        l = r + b
        r = l + a

    print(-1)

a, b, c = map(int, input().split())
solve(a,b,c)

Python: import math
a, b, c = map(int, input().split())
for k in range(60):
  t = math.ceil((k * (a + b) - c) / 60)
  if t <= (k * (a + b) + b - c) / 60:
    print(t * 60 + c)
    break
else:
  print(-1)

Python: def solve(a, b, c):
    if a == b == 30:
        print(-1)
        exit()

    l = 0; r = a;
    for t in range(114514):
        p = 60*t + c
        if l <= p <= r:
            print(p)
            exit()

        l = r + b
        r = l + a

    print(-1)

a, b, c = map(int, input().split())
solve(a,b,c)

Python: a,b,c=map(int, input().split())
d=0
for _ in range(60):
    if c<=d+a:
        print(c)
        break
    d+=a+b
    while c<=d:c+=60
else: print(-1)

Python: def solve(a, b, c):
    l = 0; r = a;
    for t in range(114514):
        t = l // 60
        p = 60*t + c
        if l <= p <= r:
            print(p)
            exit()

        l = r + b
        r = l + a

    print(-1)

a, b, c = map(int, input().split())
solve(a,b,c)

Python: from itertools import count
a,b,c=map(int,input().split())
g=set()
for n in count(0):
    p=(c+60*n)//(a+b)
    if ((a+b)*p-(c+60*n),(c+60*n)-((a+b)*p+a)) in g:
        n=-1
        break
    if (a+b)*p<=c+60*n<=(a+b)*p+a:
        break
    else:
        d=(a+b)*p-(c+60*n)
        e=(c+60*n)-((a+b)*p+a)
        g.add((d,e))
if n>=0:
    print(c+60*n)
else:
    print(n)

Python: def solve(a, b, c):
    l = 0; r = a;
    for t in range(50):
        t = l // 60
        p = 60*t + c
        if l <= p <= r:
            print(p)
            exit()

        l = r + b
        r = l + a

    print(-1)

a, b, c = map(int, input().split())
solve(a,b,c)

Python: a, b, c = map(int, input().split())
now = 0
used = [False] * 60
while True:
    sleep_start = now + a
    if now % 60 < sleep_start % 60:
        if now % 60 <= c <= sleep_start % 60:
            print(now // 60 * 60 + c)
            break
        now = sleep_start + b
    else:
        if now % 60 <= c < 60 or 0 < c <= sleep_start % 60:
            print(now // 60 * 60 + c)
            break
        now = sleep_start + b
    if now % 60 == 0:
        print(-1)
        break

Python: def solve(a, b, c):
    l = 0; r = a;
    t = 0
    for i in range(80):
        t = l // 60
        p = 60*t + c
        if l <= p <= r:
            print(p)
            exit()

        l = r + b
        r = l + a

    print(-1)

a, b, c = map(int, input().split())
solve(a,b,c)

Python: from itertools import count
a,b,c=map(int,input().split())
f=False
for n in count(0):
    p=(c+60*n)//(a+b)
    if n and d==((a+b)*p-(c+60*n)) and e==((c+60*n)-((a+b)*p+a)):
        n=-1
        break
    if (a+b)*p<=c+60*n<=(a+b)*p+a:
        break
    else:
        d=(a+b)*p-(c+60*n)
        e=(c+60*n)-((a+b)*p+a)
if n>=0:
    print(c+60*n)
else:
    print(n)

Python: a, b, c = map(int, input().split())
l = 0; r = a;

for i in range(80):
    t = l // 60
    p = 60*t + c
    if l <= p <= r:
        print(p)
        exit()

    l = r + b
    r = l + a

print(-1)

Python: import sys
A,B,C = map(int,input().split())
time = 0
ss = set()
while True:
    if time%60 == C:
        print(time)
        sys.exit()
    for t in range(A):
        time += 1
        if time%60 == C:
            print(time)
            sys.exit()
    time += B
    if (time%60) in ss:
        break
    ss.add(time%60)
print(-1)