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<vector>

using namespace std;

typedef pair<int,int> pii;
typedef vector<int> vi;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999
#define int long long int

signed main(){
    int a,b,c;
    while(cin>>a>>b>>c){
        bool f=true;
        int now=0;
        for(int i=0;i<10000000;i++){
//            cout<<now<<" "<<c<<endl;
            if(now<=c&&c<=now+a){
                cout<<c<<endl;
                f=false;
                break;
            }
            now+=a+b;
            if(now>c)c+=60;
        }
        if(f)cout<<"-1"<<endl;
    }
}

C++: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  if(60%(a+b)==0){
    if(c%(a+b)<=a){
      cout<<c<<"\n";
    }else cout<<-1<<"\n";
    return 0;
  }
  while(1){
    if(c%(a+b)<=a){
      cout<<c<<"\n";
      break;
    }
    c+=60;
    if(c>=100000000){
      cout<<-1<<"\n";
      break;
    }
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define REPR(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) \
  for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORR(i, a, b) \
  for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)
#define ALL(f, x, ...) \
  ([&](auto& y) { return (f)(begin(y), end(y), ##__VA_ARGS__); })(x)
auto INDEX = [](auto& x, auto& xs) { return &x - &xs[0]; };
void async_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
const auto inf = INT_MAX / 3;
const auto pi = 2 * std::acos(0.0);
const auto eps = 1e-14;
using ll = signed long long;
using ull = unsigned long long;

signed main() {
  async_io();
  int a, b, c;
  cin >> a >> b >> c;
  // [0..a] + [a+b % 60 .. $0 + a % 60] ...
  bool seeked[60];
  for (int i = 0, j = 0;;) {
    if (seeked[i]) {
      cout << "-1\n";
      return 0;
    }
    if (i <= c and c <= i + a) {
      cout << 60 * j + c << "\n";
      return 0;
    }
    seeked[i] = true;
    if (i + a + b >= 60) j++;
    i = (i + a + b) % 60;
  }
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b == 60) cout << -1 << endl;
	else {
		int sum = c;
		while (true) {
			if (c % (a + b) >= 0 && c % (a + b) <= a) {
				cout << sum << endl;
				break;
			}
			sum += (a + b);
		}
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  /*  (a+b)m<=60*t+c<=(a+b)*m+a
    0<=60*t+c-(a+b)*m<=a
    0 <= c-(a+b)*m<=a
    c-a<=(a+b)*m
(c-a)/(a+b)<=m


  */
  int a,b,c;
  cin>>a>>b>>c;
  rep(i,1e9){
    if(i==10000000){cout<<-1<<endl;break;}
    double m=(60*i+c-a)/(double)(a+b);
    if(m<0){cout<<c<<endl;break;}
    int mm=(int)(m+0.99999999999999);
    if(0<=60*i+c-(a+b)*mm){cout<<60*i+c<<endl;break;}
  }
}

C++: #include <iostream>

using namespace std;
const int LIMIT = 1e4;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int a,b,c;
	cin >> a >> b >> c;
	int ct = 0,t = 0,time =0;
	while(true){
		if((c + 60 - t)%60 <= a){
			time += (c + 60 - t) % 60;
			break;
		}else{
			t = (a + b) % 60;
			time += a+b;
		}
		if(time > LIMIT){
			time = -1;
			break;
		}
	}
	cout << time << 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 gcd( int m, int n )
{
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;
  while( m != n )
  {
    if ( m > n ) m = m - n;
    else         n = n - m;
  }
  return m;
}

int lcm( int m, int n )
{
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;
  return ((m / gcd(m, n)) * n);
}

int solve(int a, int b, int c){
  int max, destination;
  destination = c;
  max = lcm(a+b, 60);
  while(max > destination){
    if ((destination % (a+b) ) < a){
      return destination;
    }
    destination += 60;
  }
  return -1;
}

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  cout << solve(a, b, c) << endl;
}