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<iomanip>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<queue>	

using namespace std;

namespace MyLib {
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long
}
using namespace MyLib;

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

	return 0;
}

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

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	int x=c;
	int t=0;
	while(t<61){
		x=x-a;
		if(x<=0){
			cout<<(c+60*t)<<endl;
			return 0;
		}
		if(x<b){
			x=x+60-b;
			if(x==c){
				x=-1;
				cout<<x<<endl;
				return 0;
			}
			t++;
			continue;
		}else if (x==b){
			cout<<(c+60*t)<<endl;
			return 0;
		}else{
			x=x-b;
			continue;
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a,b,c;
  cin >> a >> b >> c;
  bool ans=false;
  for(int t=0;t<61;t++){
    if((60*t+c)%(a+b) <=a) {
      cout << 60*t+c << endl;
      ans = true;
      break;
    }
  }
  if(!ans) cout << -1 << endl;
}

C++: #include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

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

  cin>>a>>b>>c;
  int max=(a+b)*c;
  int x=a+b;
  for(i=c;i<=max;i=i+60){
    // cout<<i<<endl;
    if(i%x<=a){
      cout<<i<<endl;
      return 0;
    }
  } 

  cout<<"-1"<<endl;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 10000000;



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

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(a>=c){
		//???????????????????????????
		cout << c << endl;
		return 0;
	}
	REP(i,60){
		c += 60;
		int d = c % (a+b);
		if(d<=a){
			//???????????? ??????
			cout << c << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

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

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

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

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c; cin >> a >> b >> c;
  int st = 0;
  st += c / (a + b) * (a + b);
  c -= st;
  if(a >= c) {
    cout << st + c << endl;
    return 0;
  }
  if((a + b) % 60 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int up = 0;
  while(1) {
    if(up + a >= c) {
      cout << st + c << endl;
      return 0;
    }
    if(up + a < c && up + a + b > c) c += 60;
    up += a + b;
  }
}