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;
  cin>>a>>b>>c;
  if(a+b==60&&a<c){
    cout<<-1<<endl;
    return 0;
  }
  int nt=0;
  for(int i=0;i<10000;i++){
    if(nt%60<=c&&c<=(nt+a)%60){
      cout<<nt+c-(nt%60)<<endl;
      return 0;
    }
    nt+=a;
    nt+=b;
  }
  cout<<-1<<endl;

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int main() {
	int a,b,c,t=0;
	cin>>a>>b>>c;
	int ans;
	while(true){
		if(t>=1000007){
			ans=-1;
			break;
		}
		if((c+60*t)%(a+b)<=a){
			ans=c+60*t;
			break;
		}
		t++;
	}
	cout<<ans<<endl;
}

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

int main()
{
  int a,b,c,n=1,T[4000];
  
  cin>>a>>b>>c;
  while(n<4000){
    for(int i=0;i<a;i++,n++)T[n]=1;
    for(int i=0;i<b;i++,n++)T[n]=0;
  }
  for(int i=c;i<4000;i+=60){
    if(T[i]==1){
      cout<<i<<endl;
      break;
    }
    if(i>3600){
      cout<<-1<<endl;
      break;
    }
  }
  return 0;
}

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

int main(){
    int a,b,c,sum=0,n=0;
    cin >> a >> b >> c;
    
    if(60 % (a+b) == 0 && a < c){
        printf("-1\n");
    }else{
        while(1){
            n += a; sum+=a;
            if(n>c){
                printf("%d\n",sum-(n-c));
                break;
            }
            n += b; sum+=b;
            if(n > 60)
                n -= 60;
            
        }
    }
    
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

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

	int v[100100];
	rep(i, 100000) v[i] = 0;

	for (int i = 0; i < 10000; i += (a + b)){
		reps(j, i, i + a) v[j] = 1;
	}

	int cnt = 0;
	for (int i = c - 1; i <= 10000; i += 60){
		cnt++;
		if(v[i] == 1){
			printf("%d\n", c + ((cnt - 1) * 60));
			return 0;
		}
	}

	printf("-1\n");
	return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF INT_MAX
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int t=0;
    for(int i=0;;i++){
        if(i%2==0){
            rep(j,0,a){
                t++;
                if(t%60==c && t>=c){
                    cout<<t/60*60+c<<endl;
                    return 0;
                }
            }
        } 
        else t+=b;
        if(t>=10000000){
            cout<<-1<<endl;
            return 0;
        }
    }
    
    
    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;

	while(t % (a+b) <= a){
		cout << t << endl;
		return 0;
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)

int main(void){
  int a,b,c;
  cin>>a>>b>>c;
  if(a>=c){
    cout<<c<<endl;
    return 0;
  }
  int n = 10000;
  int sum = c;
  int cnt = 0;
  while(n--){
    
    //cout<<cnt<<" "<<sum<<" "<<cnt+b<<endl;
    while(cnt > sum)sum += 60;
    if(cnt <= sum && sum <= cnt + b){
      cout<<sum<<endl;
      //  break;
      return 0;
    }
    
    cnt += a + b;
  }
  cout<<-1<<endl;
}

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int A=read(),B=read(),C=read();
	int time=0;
	bool sleep=false;
	int t=0;
	int i=0;
	while(i<10000){
		time += A;
		if(time >= C){
			cout << C << endl;
			return 0;
		}
		time += B;
		if(time > C) C += 60;
		
		if(time == 60){
			cout << -1 << endl;
			return 0;
		}
		i++;
	}
	
	cout << -1 << endl;

}