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;

int a;
int b;
int c;
set<int> considered;

int main() {
  scanf("%d%d%d", &a, &b, &c);
  
  int k = 0;
  int ans = 0;
  while (1) {
    if (considered.count(k)) {
      puts("-1");
      return 0;
    }

    if ((k <= c && c <= k+a) || (k <= c+60 && c+60 <= k+a)) {
      printf("%d\n", ans*60 + c);
      return 0;
    }

    considered.insert(k);
    k = k+a+b;
    if (k >= 60) {
      k %= 60;
      ans++;
    }
  }
}

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 && (60 / (a + b)) % 2 == 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 a,b,c;
  cin>>a>>b>>c;
  if(a+b==60&&a<c){
    cout<<-1<<endl;
    return 0;
  }
  int nt=0;
  for(int i=0;i<60;i++){
    if(nt%60<=c&&c<=(nt+a)%60){
      cout<<nt+c-(nt%60)<<endl;
      return 0;
    }
    nt+=a;
    nt+=b;
  }
  cout<<-1<<endl;

  return 0;
}

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

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

  cin >> a >> b >> c;
  i=0;
  j=a;
  k=c;
  if (60%(a+b)==0&&c%(a+b)>a){
    cout << -1 << endl;
    return 0 ;
  }
  while (1){
    if (i<=k&&k<=j){
      cout << k << endl;
      break;
    }
    i+=a+b;
    j+=a+b;
    if (k<i){
      k+=60;
    }
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

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

	cin >> a >> b >> c;
	
	if(a >= c){
		cout << c << endl;
		return 0;
	}

	if((a+b)%60 == 0){
		cout << -1 << endl;
		return 0;
	}

	int t = c;
	while(t % (a+b) <= a){
		cout << t << endl;
		return 0;
	}

	return 0;
}

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

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

int a, b, c;

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

  if (60 % (a + b) == 0) {
    int k = 60 / (a + b);
    bool ok = false;
    for (int i = 0; i < k; i++) {
      if (i * (a + b) <= c && c <= i * (a + b) + a) ok = true;
    }
    if (ok)
      cout << c << endl;
    else
      cout << -1 << endl;
  } else {
    int loop = 0;
    bool p = true;
    int sum = 0;
    int ans = 0;
    if (c <= a) {
      cout << c << endl;
      return 0;
    }
    while (0 <= loop) {
      if (p) {
        sum += a;
        ans += a;
      } else {
        sum += b;
        ans += b;
      }
      sum %= 60;

      if (p && sum == a && loop != 0) {
        cout << -1 << endl;
        return 0;
      }
      if (!p) {
        if (sum <= c && c <= sum + a) {
          ans += c - sum;
          cout << ans << endl;
          return 0;
        }
      }

      p = !p;
      loop++;
    }
  }

  return 0;
}

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

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    constexpr int RARY = 60;
    for (int i = 0; i < 60000; i++) {
        const int t = (c + i * RARY);
        const int tim = t % (a + b);
        if (tim <= a) {
            cout << t << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    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;
  int up = 0;
  FOR(i,0,1000) {
    if(up + a >= c) {
      cout << st + c << endl;
      return 0;
    }
    if(up + a < c && up + a + b > c) c += 60;
    up += a + b;
  }
  cout << -1 << endl;
  return 0;
}

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

#define ll long long int
#define ld long long double
#define reps(i,f,n) for(int i=f;i<n;i++)
#define rep(i,n) reps(i,0,n)
#define m1 cout<<"move1"<<endl
#define m2 cout<<"move2"<<endl
#define m3 cout<<"move3"<<endl
#define m4 cout<<"move4"<<endl

int main(){
  int flag = 1;
  int a,b,c;
  int t=0;
  int c_ans;

  cin>>a>>b>>c;
  c_ans = c;

  while(1){
    if( c+60*t - a <= 0 && flag == 1){
      //m1;
      cout<< c_ans + 60*t<<endl;
      break;
    }
    //else if(c + 60 * t - a <=0 && flag == 1){
    //t++;
    //flag = 0;
    //}
    else if(c + 60 * t - a >= 0 && flag == 1){
      //m2;
      c-=a;
      flag = 0;
    }
    else if(c + 60 * t - b == 0 && flag == 0){
      //m3;
      cout<<c_ans + 60 * t <<endl;
      break;
    }
    else if(c + 60 * t - b < 0 && flag == 0){
      if( 60 % ( a + b ) == 0){
	cout<<-1<<endl;
	break;
      }
      else{
	t++;
      flag = 1;
      c-=b;
      // m4;
      }
    }
    else {
      c -= b;
      flag = 1;
    }
  }

  return 0;
}