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 <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) {}
};

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<Edge>> AdjList;
AdjList graph;

const int INF = 100000000;

LL N, M;

map<int, char> mp;

int main() {
    //cout << fixed << setprecision(15);
    int n;
    LL a, b, c; cin >> a >> b >> c;
    vector<pair<int, int> >vp;
    vp.push_back({0, a});
    int cnt=1;
    while(cnt!=500){
        vp.push_back({cnt*(a+b), (cnt+1)*a + cnt*b});
        cnt++;
    }

    vector<int> v;
    for(int i=0; i<1000; ++i){
        v.push_back(60*i+c);
    }

    REP(i, 500){
        REP(j, vp.size()){
            if(v[i] < vp[j].first) break;

            if(v[i]>=vp[j].first && v[i]<=vp[j].second){
                cout << v[i] << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

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

using namespace std;

void solve(int a,int b,int c) {
    int t = 0;
    for(int i=0; ; i+=a+b) {
        c += 60*t;
        if(i<=c and c<=i+a) {
            cout << c << "\n";
            return ;
        }
        ++t;
        if(t > 1e5) break;
    }
    cout << -1 << "\n";
}

int main() {
    int a,b,c; cin>>a>>b>>c;
    solve(a,b,c);
    return 0;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  bool flag = true;
  int time = 0, cnt = 0;
  for(int i = 0; i < 1e8; i++){
    if(time <= c && c <= time + a){
      cout << 60*cnt + c << endl;
      flag = false;
      break;
    }
    time += a + b;
    if(time > 60){
      cnt++, time -= 60;
    }
  }
  if(flag)cout << -1 << endl;
}

C++: #include <cstdio>
#include <cstdint>
#include <algorithm>
#include <utility>
#include <vector>

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

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;
    while(1){
      if(t>100000){
	cout<<"-1"<<endl;
	break;
      }
        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>
using namespace std;

int GCD(int m, int n)
{
	if (n == 0)return m;
	return GCD(n, m % n);
}

int main()
{
	int a, b, c, gcd, n, res = -1;
	cin >> a >> b >> c;
	gcd = GCD(60,c);
	n = 60/gcd + (a+b);
	for (int i = 0; i < n; i++) {
		if ((c + 60 * i) % (a + b) >= 0 && (c + 60 * i) % (a + b) <= a) {
			res = c + 60 * i;
			break;
		}
	}
	cout << res << endl;
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    
    cin >> a >> b >> c;
    
    while(c < 1000000)
    {
        if(0 <= c % (a + b) && c % (a + b) <= a)
        {
            cout << c << endl; return 0;
        }
    }
    
    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;
}