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<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;



int main() {
	
	int a, b, c;
	cin >> a >> b >> c;
	
	int ans = -1;
	rep(i, 100){
		int tmp = 60 * i + c;
		if(tmp % (a + b) <= a){
			ans = tmp;
			break;
		}
	}

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

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if( a + b == 60 ) cout << -1 << endl;
  else if( c <= a ) cout << c << endl;
  else if ( c > a ){
    if( a + b > 60 ){
      c -= a + b - 60;
      c += a + b;
      cout << c << endl;
    }else if ( a + b < c ){
      cout << c << endl;
    }else if ( a + b > c ){
      int time = 0;
      while(1){
	time += a + b;
	if( time > 60 ){
	  int tmp = time -60;
	  int temp = c - tmp;
	  //  cout << "temp" << " " << temp << " " << "c" << " " << c << " " << "time" << " " << time << endl;
	  time += temp;
	  
	    cout << time << endl;
	    break;
	}
      }
    }
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100000

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

  scanf("%d%d%d",&a,&b,&c);

  int t = 0;
  
  for(int i=0;i<60;i++){
    if(t<=c && c<=t+a){
      printf("%d\n",c);
      return 0;
    }
    t += a + b;
    while(t>c) c+=60;
  }
    
  puts("-1");
  
  return 0;
}

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

int main(){
    int a, b, c;
    int d=0;
    int n=0;
    cin >> a >> b >> c;
    while(true){
        if(d<=c && c<=d+a){
            cout << n*60 + c << endl;
            break;
        }
        d+=a+b;
        if(d>60){
            n+=d/60;
            d%=60;
        }
        if(d==0){
            cout << -1 << endl;
            break;
        }
    }
}

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

int main(){

  int a,b,c,t=0,af,bf,end;
  cin>>a>>b>>c;
    af=a,bf=a+b,end=c;
    if(a>=c) cout<<c<<endl;
   else if(a+b==60 && a<c) cout<<"-1"<<endl;
  else {
    while(1){
        if( end<=af){
	cout<<60*t+c<<endl;
	break;
      }
 if(end>af && bf>=end)t++;
      af=a+bf;
      bf=af+b;
      end=(60*t)+c;
    }
      
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<unordered_set>
using namespace std;

int main() {
	unordered_set<int>u;
	int a, b, c;
	cin >> a >> b >> c;
	for (int d = 0;; d++) {
		int e = d * 60 + c;
		int f = e % (a + b);
		if (f <= a) { cout << e << endl; return 0; }
		if (u.find(f) != u.end()) { puts("-1"); return 0; }
		else u.insert(f);
	}
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool cheak(ll x, ll y, ll xMax, ll yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline ll toInt(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 9;

int main(){

	int a, b, c;
	cin >> a >> b >> c;

	int t = 0, cnt = 0,acnt = 0, bcnt = -1;

	while (true){
		if (cnt >= 1e7)break;
		if (60 * t + c == cnt && bcnt <= 0){
			cout << cnt << endl;
			return 0;
		}
		if (bcnt == -1){
			if (++acnt == a){
				acnt = -1;
				bcnt =  0;
			}
		}else
		if (acnt == -1){
			if (++bcnt == b){
				acnt =  0;
				bcnt = -1;
			}
		}
		if (cnt++ == 60)t++;
	}
	cout << -1 << endl;

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

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

  REP(k,0,10000){
    REP(i,1,10000){
      if((a + b)*i - 60*k <= c && c <= (a + b)*i + a - 60*k){
        cout<<c + 60*k<<endl;
        return 0;
      }
    }
  }

  return 0;
}