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++: #define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    long long a, b, c; cin >> a >> b >> c;
    long long now = 0;
    for (int i = 0; i < 10000000; i++) {
        if (c%(a+b) <= a) {
            cout << c << endl;
            return 0;
        }
        c += 60;
    }
    cout << -1 << endl;
    return 0;
}

C++: # define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 
typedef vector<int> vi;


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int now = 0;
	while (now <= 10000)
	{
		for (int i = 0; i <= a; i++)
		{
			if (now > c)c += 60;
			if (now == c)
			{
				cout << now << endl;
				return 0;
			}
			now++;
		}

		for (int i = 0; i < b-1; i++)
		{
			now++;
			if (now > c)c += 60;
		}
	}


	cout << -1 << endl;
	return 0;
}

C++: #include<iostream>


#define FOR(i,a,b) for(int i = a;i < b;i++)
#define RFOR(i,a,b) for(int i = a;i >= b;i--)
#define IN cin >> 
#define OUT cout <<
#define E  << endl;

using namespace std;


int goal_time = 0;

int a, b, c;

void input() {
	IN a >> b >> c;
}

int main() {
	input();
	int memo = 0;
	if ((60 % (a + b) == 0) &&  c > a) {
		OUT - 1 E
		return 0;
	}
	bool flag = false;
	goal_time += c;
	while (true) {
		int n = memo;
		while (true){
			if ((a + b) * n <= goal_time && (a + b) * n + a >= goal_time) {
				OUT goal_time E
				flag = true;
				break;
			}
			if ((a + b) * n > goal_time) {
				memo = n;
				break;
			}
			n++;
		}
		if (flag)break;
		goal_time += 60;
	}

	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>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#define fcout(n) cout<<fixed<<setprecision((n))
using namespace std;
int main(){
	int a,b,c,t=0;
	cin>>a>>b>>c;
	while(1){
		if(c%(a+b)>a&&(c+60)%(a+b)==c%(a+b)){
			t=-1;
			break;
		}
		if((c+60*t)%(a+b)<=a){
			break;
		}
		else t++;
	}
	if(t==-1) cout<<-1<<endl;
	else cout<<60*t+c<<endl;
}

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

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

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,c;
    cin>>a>>b>>c;
    int l=0,r=a;
    REP(i,1e5){
        while(c<l) c+=60;
        if(c<=r){
            cout<<c<<endl;
            return 0;
        }else{
            l+=a+b,r+=a+b;
        }
    }
    cout<<-1<<endl;
}

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

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

	int start = 0, end, t=c;
	bool flag = false;
	while (start <= 3600+c) {
		end = start + a;
		if (start <= t && t <= end) {
			flag = true;
			break;
		}

		start = end + b;
		t = 60 * (start/60) + c;
	}
	if(flag) cout << t << endl;
	else cout << -1 << endl;
    return 0;
}