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)
}

C++: #include<iostream>
using namespace std;

int main()
{
    int a, b, c, d, e = -1, t = 0;

    cin >> a >> b >> c;

    while(1)
    {
        d = 60 * t + c - ( a + b ) * ( ( 60 * t + c ) / ( a + b ) );
        if( d == e || t > 1000 )
        {
            cout << -1 << endl;
            break;
        }
        e = d;
        if( d - a <= 0 )
        {
            cout << 60 * t + c << endl;
            break;
        }
        else
            t++;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    bool ok=true;
    cin>>a>>b>>c;
    for (int i=1; i<=3600 && ok; i++)
    {
        if (i%60==c && i%(a+b)<=a) { cout<<i<<'\n'; ok=false; }
    }
    if (ok) cout<<"-1\n";
    return 0;
}

C++: #include<iostream>
#include<set>
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    int ans = c;
    set<int> s;
    while(ans % (a+b) > a){
        if(s.count(ans%(a+b))){
            ans = -1;
            break;
        }
        s.insert(ans%(a+b));
        ans += 60;
    }

    cout << ans << endl;
    
    return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int res = -1;
    for (int i = 0; i < 10000; i++) {
        int to = 60 * i + c;
        if (to % (a + b) <= a) {
            res = to;
            break;
        }
    }
    cout << res << endl;
    return 0;
}

C++: #include<iostream>
using namespace std;

//??????????????§
int a,b,c;

//???????§?????????????
int start;

//????????£?????????
int time;

//?????????????????????????????????
bool can;

int main() {
	//??\???
	cin>>a>>b>>c;

	//?????????
	can=false;
	start=0;
	time=0;

	do {
		//????????????????????????
		if(start<=c && c<=start+a){
			time+=(c-start);
			can=true;
			break;
		}

		//??????????????????????¬???????????????????
		start+=(a+b);
		start%=60;

		time+=(a+b);
	}while(start!=0);

	//??????
	if(can)cout<<time<<endl;
	else   cout<<-1<<endl;

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define REPR(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) \
  for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORR(i, a, b) \
  for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)
#define ALL(f, x, ...) \
  ([&](auto& y) { return (f)(begin(y), end(y), ##__VA_ARGS__); })(x)
auto INDEX = [](auto& x, auto& xs) { return &x - &xs[0]; };
void async_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
const auto inf = INT_MAX / 3;
const auto pi = 2 * std::acos(0.0);
const auto eps = 1e-14;
using ll = signed long long;
using ull = unsigned long long;

signed main() {
  async_io();
  int a, b, c;
  cin >> a >> b >> c;
  // [0..a] + [a+b % 60 .. $0 + a % 60] ...
  bool seeked[60] = {};
  for (int i = 0, j = 0;;) {
    if (seeked[i]) {
      cout << "-1" << endl;
      return 0;
    }
    if (i <= c and c <= i + a) {
      cout << 60 * j + c << endl;
      return 0;
    }
    seeked[i] = true;
    if (i + a + b >= 60) j++;
    i = (i + a + b) % 60;
  }
}

C++: #include<iostream>


#define FOR(i,a,b) for(int i = a;i < b;i++)
#define RFOR(i,a,b) for(int i = a;i >= b;i--)
#define IN cin >> 
#define OUT cout <<
#define E  << endl;

using namespace std;


int goal_time = 0;

int a, b, c;

int x = 0;

void input() {
	IN a >> b >> c;
}

int main() {
	input();
	int memo = 0;
	if ((60 % (a + b) == 0) &&  c > a) {
		OUT - 1 E
		return 0;
	}

	x = 60.0 / (a + b);
	if (x == 0)x = 1;

	bool flag = false;
	goal_time += c;
	while (true) {
		int n = memo;
		while (true){
			if ((a + b) * n <= goal_time && (a + b) * n + a >= goal_time) {
				OUT goal_time E
				flag = true;
				break;
			}
			if ((a + b) * n > goal_time) {
				memo = n;
				break;
			}
			n += x;
		}
		if (flag)break;
		goal_time += 60;
	}

	return 0;
}