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 <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	ll a, b, c; cin >> a >> b >> c;
	int kkt = 89;
	set<ll> s;
	int cur = 0;
	while (kkt) {
		if (s.find(cur % 60) != s.end()) {
			puts("-1");
			return 0;
		}
		for (int i = 1; i <= a; i++) {
			if ((cur + i) % 60 == c) {
				cout << cur + i << endl;
				return 0;
			}
		}
		s.emplace(cur % 60);
		cur += a + b;
	}
	return 0;

}

C++: #include<iostream>
using namespace std;
int main(){
int n,m,b,c;
cin>>n>>m>>b;
for(int i=0;i<100;i++){
if((b+i*60)%(n+m)<=n){
c=b+i*60;
break;
}
}
c=-1;
cout<<c<<endl;
return 0;
}

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

int main() {
    int ot, nt, ct, dt;
    cin >> ot >> nt >> ct;
    dt = ct;
    while(true) {
        if(dt % (ot + nt) <= ot) {
            cout << dt << endl;
            return 0;
        } else {
            if(60 % (ot + nt) == 0) {
                cout << -1  << endl;
                return 0;
            }
            dt += 60;
        }
    }
}

C++: #include<iostream>

using namespace std;

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

	cin >> a >> b >> c;
	
	/*
	(a+b)*t <= 60t+c <= (a+b)*t+a
	*/

	if(c <= a){
		cout << c << endl;
		return 0;
	}

	if(a+b == 60){
		cout << -1 << endl;
		return 0;
	}

	int left = c/(-60+a+b);
	double right = (c-a)/(-60+a+b);
	if(right <= left)
		cout << 60*left+c << endl;

	return 0;
}

C++: #include<iostream>

using namespace std;

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

	cin >> a >> b >> c;
	
	if(a >= c){
		cout << c << endl;
		return 0;
	}

	if((a+b)%60 == 0){
		cout << -1 << endl;
		return 0;
	}

	int t;
	if(c <= a + b) t = c + 60;
	else t = c;

	int i = 0;
	while(t % (a+b) > a && i < 60){
		t += 60;
		i++;
		if(i < 60){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << t << endl;

	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;
typedef pair<ll, ll> Pll; 

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if (a+b == 60 && c > a) {
		cout << -1 << endl;
		return 0;
	}
	while (1) {
		if (c < 0) {
			cout << -1 << endl;
			break;
		}
		if (c % (a+b) <= a) {
			cout << c << endl;
			break;
		}
		else c += 60;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int k = 0;
    while(1){
        if(k >= 61){
            cout << "-1\n";
            break;
        }
        if((60*k+c) % (a+b) <= a){
            cout << 60*k+c << "\n";
            break;
        }
        k++;
    }
    return 0;
}