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;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int main(){
    int a, b, c; scanf("%d%d%d", &a, &b, &c);
    if(a >= c){
        printf("%d\n", c);
        return 0;
    }
    if(a + b == 60){
        puts("-1");
        return 0;
    }
    int now = a + b;
    while(true){
        int k = now % 60;
        bool f = false;
        if(k + a <= 60 && c <= k + a && k <= c) f = true;
        if(k + a > 60 && c <= (k + a) % 60 && k <= c) f = true;
        if(f){
            now += c - k;
            break;
        }
        now += a + b;
    }
    printf("%d\n", now);
    return 0;
}

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

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

  int cur = 0;
  for(int i=0;i<100;i++){
    if(cur%60 <= c && c <= cur%60+a){
      cout << cur/60*60 + c << endl;
      return 0;
    }
    cur += a;
    if(c <= cur%60){
      cout << cur/60*60 + c << endl;
      return 0;
    }
    cur += b;
  }
  cout << -1 << endl;
}

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 (a + b == 60 && 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<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  int tmp=0;
  bool wakeup=true;
  int t=0;
  while(1){
    if(wakeup){
      if(tmp<=c&&c<=tmp+a){
        cout<<60*t+c<<endl;
        break;
      }
      tmp+=a;
      wakeup=false;
    }else{
      tmp+=b;
      wakeup=true;
    }
    if(tmp>=60){
      tmp%=60;
      t++;
    }
    if(t>60){
      cout<<-1<<endl;
      break;
    }
  }
  return 0;
}

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int a, b, c, t = 0;
  cin >> a >> b >> c;
  for (int i = 0; ; ++i) {
    if (t % 60 <= c && c <= t % 60 + a) {
      cout << t + c - t % 60 << endl;
      return 0;
    }
    t += a + b;
    if (t > 3600) break;
  }
  cout << -1 << endl;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int a, b, c; cin >> a >> b >> c;
	int ans = -1; int ab = a + b;
	rep(i, 0, 60) {
		int arrive = i * 60 + c;
		if (arrive%ab <= a) {
			ans = arrive;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int loop = 0;
    int time = 0;
    for(;;) {
        time += a;
        if (time >= c) {
            cout << 60 * loop + c << endl;
            break;
        } 
        time = (time + b) % 60;
        if (time == 0) {
            cout << -1 << endl;
            break;
        }
        loop++;
    }
}

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

int a, b, c;

int main() {
	cin >> a >> b >> c;
	int i, j, t = 0;
	for( i = 0; i < 100; i++) {
		for( j = 0; j <= a; j++) {
			if (t % 60 == c)
				break;
			t += (j < a);
		}
		if ( j <= a )
			break;
		t += b;
	}
	if ( i < 100 )
		cout << t << endl;
	else
		cout << -1 << endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int a,b,c;

int main(){
	cin.sync_with_stdio(false);
  cin>>a>>b>>c;
  rep(i,61){
    int start=(a+b)*i,end=(a+b)*i+a;
    int l,u;
    if(end-c<0)continue;
    if(start-c<0)l=0;
    else l=(start-c+59)/60;
    u=(end-c)/60;
    if(l<=u){
      cout<<c+60*l<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
	return 0;
}