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 <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <set>
#include <map>
//#include <bits/stdc++.h>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

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

	int a, b, c; cin >> a >> b >> c;
	int t = 1, t_ans = 0;
	int i = 1, or = 0;
	while (1)
	{
		if (a + b == 60 && t_ans > 5) 
		{
			printf("-1\n"); 
			break;
		}
		if (t == 60){ t = 0; t_ans++; }
		t++;
		if (i == a && or == 0){ i = 0; or = 1; }
		else if (i == b && or == 1){ i = 0; or = 1; }
		else if (i <= b && or == 0 && t == c)
		{ 
			printf("%d\n", (60 * t_ans) + c); 
			break;
		}
		i++;
	}
	
	return 0;
}

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



int main(){

  int a, b, c;

  cin >> a >> b >> c;

  int cnt = 0;

  int x1 = 0, x2 = a;

  if(60 % (a+b) == 0){
    while(1){
      if(c >= x1 && c <= x2){

	cout << c << endl;
	break;
      }else{
	x1=x2+b;
	x2=x1+a;
      }
      if(x1 > c){
	cout << -1 << endl;
	break;
      }
    }

  }else {
    int cp = c;
    while(1){


      if(cp < x1){
	cp += 60;
	//	cout << cp << endl;
	cnt++;
      }
      if(cp >= x1 && cp <= x2){
	cout << cp << endl;
	break;
      }else{
	x1=x2+b;
	x2=x1+a;
      }
    }
  }



}

C++: #include <iostream>
#include <set>

using namespace std;
typedef pair<int, int> P;
static const int INF = 1e9;

void solve()
{
	int a[2], c;
	cin >> a[0] >> a[1] >> c;
	if (a[0] >= c)
	{
		cout << c << endl;
		return;
	}
	set<P> Set;
	int diff = INF;
	int now = a[0];
	int cnt = 0;
	while (true)
	{
		int preDiff = diff;
		diff = c - now;
		if (Set.find(make_pair(diff, preDiff)) != Set.end())
		{
			cout << -1 << endl;
			return;
		}
		Set.insert(P(diff, preDiff));
		while (now < c)
		{
			++cnt;
			now += a[cnt % 2];
			if (now >= c)
			{
				if (cnt % 2 == 1)
				{
					break;
				}
				else
				{
					cout << c << endl;
					return;
				}
			}
		}
		c += 60;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <iostream>

using namespace std;


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

C++: #include<iostream>

using namespace std;
int d[60];
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int t=c;
	int now=0;
	int ans=0;
	while(1){
		d[now%60]++;
		if(d[now%60]>1){
			ans=-1;
			break;
		}
		if(now>t)t+=60;
		if(now+a>=t && t>=now){
			ans=t;
			break;
		}
		now+=a+b;
	}
	cout<<ans<<endl;
}

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



int main(){

  int a, b, c;

  cin >> a >> b >> c;

  int cnt = 0;

  int x1 = 0, x2 = a;


  if(60 % (a+b) == 0){
    int cp = c;
    while(1){
      if(cp < x1){
	cp += 60;
	cout << -1 << endl;
	break;
      }
      if(c >= x1 && c <= x2){
	
	cout << c << endl;
	break;
      }else{
	x1=x2+b;
	x2=x1+a;
      }
      
    }

  }else {
    int cp = c;
    while(1){


      if(cp < x1){
	cp += 60;
	//	cout << cp << endl;
	cnt++;
      }
      if(cp >= x1 && cp <= x2){
	cout << cp << endl;
	break;
      }else{
	x1=x2+b;
	x2=x1+a;
      }
    }
  }



}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int start_a = 0,start_b = a;
  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<iostream>
int main(){
int n,m,b,c;
std::cin>>n>>m>>b;c=b;
for(int i=0;i<99;i++){
if(c%(n+m)<=n)goto a;
c+=60;
}
c=-1;
a:
std::cout<<c<<"\n";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();
	if (a + b == 60 && c > a) {
		OUT - 1 E
			return 0;
	}
	bool flag = false;
	goal_time += c;
	while (true) {
		int n = 0;
		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) {
				break;
			}
			n++;
		}
		if (flag)break;
		goal_time += 60;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int mod=c%(a+b);
    if(mod<=a) printf("%d\n",c);
    else if(60%(a+b)==0) printf("-1\n");
    else {
        int ans=c;
        while((mod+60)%(a+b)<=a) mod=(mod+60)%(a+b),ans+=60;
        printf("%d\n",ans);
    }
}

C++: #include <iostream>
using namespace std;
int main(){
  int a,b,c,as,af,end;
  cin >> a >> b >> c;
  as=0,af=a;
  end=c-af;
  while(1){
    if(as<=c&&c<=af){
      cout << c << endl;
      break;
    }
    as+=a+b,af+=a+b;
    if(as>c) c+=60;
    if(c-af==end){
      cout << -1 << endl;
      break;
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  bool ok = false;
  for (int i = 0; i < a + b; i++){
    int t = 60 * i + c;
    int r = t % (a + b);
    if (r <= a){
      cout << t << endl;
      ok = true;
      break;
    }
  }
  if (!ok){
    cout << -1 << endl;
  }
}