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>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PI;
using namespace std;
#define MAX  999999
int main(){
    int a,b,c; cin >> a>>b>>c;
    int sum = a+b; int ans = 0;
    for(int i = 0;10000;i++){
        ans=i*60+c;
        if(ans % (a+b)<=a){cout << ans << endl; break;}
        if(a == b && a+b == 60){cout << -1 << endl; break;}
    }
    
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int T=0;
    while(true){
        if(T>3600){
            cout<<-1<<endl;
            return 0;
        }
        T+=a;
        if(c<=T){
            cout<<c<<endl;
            return 0;
        }
        T+=b;
        if(c<T) c+=60;
    }

    return 0;
}

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

int main(){
  int a, b, c, t = 0, e = 0, temp;
  int i, j, k;
  cin>>a>>b>>c;

  while(1){
    if(t%60 <= c && c <= t%60 + a){//cout<<t<<endl;
	  t = t/60 * 60 + c ;
	  break;
	}
    if(t/60 >= 1 && t%60 ==0){
      t = -1;
      break;
    }
	t += a + b;
  }
  
  
  cout<<t<<endl;
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>
using namespace std;



int main(){
	
	
	bool f[100]={};
	int a,b,c;
	cin>>a>>b>>c;
	int ans=0,y=0;;

	while(1){
		if(f[y]){cout<<"-1"<<endl;break;}
		int x=y%60;
		f[y]++;
		if(c>=y&&c<=y+a){
			ans+=(c-y);
			cout<<ans<<endl;
			break;
		}
		else if(c<y&&(y+a)%60>=c){
			ans+=60-y+c;
			cout<<ans<<endl;
			break;
		}
		else {y+=a+b;
		ans+=a+b;
		y%=60;
		}


	}
	

	return 0;
}

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

cout << "10" << endl;

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int now=0,t=0;
  while(1){
    now+=a;
    if(now>=60*t+c){
      cout<<60*t+c<<endl;
      break;
    }
    now+=b;
    if(now==60*t+c){
      cout<<now<<endl;
      break;
    }
    if(now>60*t+c)t++;
    if(now%60==0){
      cout<<-1<<endl;
      break;
    }
  }
  return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int a,b,c;

int main(){
	cin.sync_with_stdio(false);
	cin>>a>>b>>c;
	int time=0;
	while(1){
		time+=a;
		if(time>=c){
			time=c;
			break;
		}
		time+=b;
		while(time>c)c+=60;
		if(time%60==0){
			time=-1;
			break;
		}
	}
	cout<<time<<endl;
	return 0;
}

C++: #include <iostream>

using namespace std;

int gcd(int m, int n)
{
	while(1) {
		if (m == n) break;
		if (m > n) m = m - n;
		else n = n - m;
	}
	return m;
}

int lcm(int x, int y)
{
	return x * y / gcd(x, y);
}

int main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	int get = lcm(a + b, 60);
	int max = get / 60;
	int ans = - 1;
	for (int i = 0; i < max; i++) {
		int time = 60 * i + c;
		if (time % (a + b) <= a) {
			ans = time;
			break;
		}
	}

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

C++: #include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    bool visited[60];
    int d = 0, e = 0;
    while (1) {
        if (visited[d]) break;
        visited[d] = true;
        if (d + a >= c) {
            cout << c - d + e << endl;
            return 0;
        }
        d = (d + a + b) % 60;
        e += a + b;
    }
    cout << -1 << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
	cin>>a>>b>>c;
	for(int i=0;i<100000;i++){
		int t=60*i+c;
		if(t%(a+b)<=a){
			cout<<t<<endl;
			return 0;
		}
	}
	puts("-1");
}