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>
using namespace std;

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

  cin >> a >> b >> c;

  i=a;
  j=c;
  while (1){
    if (i>=j) {
      cout << j << endl;
      break;
    }
    if (a+b==60) {
      cout << -1 << endl;
      break;
    }

    i+=a+b;

    j+=60;
  }
  return 0;
}

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

int gcd(int m, int n) {
  int t;
  if ((!m) || (!n)) return 0;
  while (m%n) {
    m = m%n;
    t = n;
    n = m;
    m = t;
  }
  return n;
}

int main() {
  int a, b, c, t, d;
  cin >> a >> b >> c;
  d = gcd(60,a+b);
  if (a >= c%d) {
    t = c;
    while (t%(a+b) > a) t += 60;
    cout << t << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

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

int main() {
    int ot, nt, ct, dt;
    cin >> ot >> nt >> ct;
    dt = ct;
    while(true) {
        if(dt % (ot + nt) <= ot) {
            cout << dt << endl;
            return 0;
        } else {
            if((ot + nt) % 60 == 0) {
                cout << -1  << endl;
                return 0;
            }
            dt += 60;
        }
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;

int solve(int a, int b, int c) {

    int t=0;
    int cnt=0;

    for (int i=0; i<100000; ++i) {

        if (t <= c and c <= t+a) {
            return 60 * cnt + c;
        }

        if (t + a >= 60) {
            if (0 <= c and c <= (t+a)%60) {
                return 60 * cnt + c;
            }
        }

        t = ( t + a + b );
        if (t >= 60) {
            cnt++;
            t %= 60;
        }
    }

    return -1;

}

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

    cout << solve(a, b, c) << endl;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int a,b,c;

void solve(){
  int t=0,now=0;
  bool ok=false;
  while(1){
    if(now>=100000)break;
    if(now<=60*t+c&&60*t+c<=now+a){
      cout<<60*t+c<<endl;
      ok=true;break;
    }else if(now<=60*t+c){
      now+=(a+b);
    }else{
      t++;
    }
  }
  if(!ok)cout<<-1<<endl;
}

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

C++: #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

//ユークリッドの互除法で最大公約数を求める
int gcd( int p, int q ) {
	if( q == 0 ) return p;
	return gcd( q, p % q );
}

int main(void){

	/*
		睡眠の周期はa+b分
		睡眠と山手線の周期はlcm( a+b, 60 )
		0からlcm( a + b, 60 )までを調べれば十分？
	*/

	int a, b, c;
	int lcm;
	bool flg = false;
	int ans = 0;

	cin >> a >> b >> c;
	lcm = ( a + b ) * 60 / gcd( ( a + b ) , 60 );

	int t = 0;
	while( t <= lcm ) {
		for( int i = 0; i <= a; i++ ) {
			int tmp = t + i;
			if( tmp % 60 == c ) {
				flg = true;
				ans = tmp;
			}
		}
		if( flg ) break;
		t += ( a + b );
	}

	if( !flg ) 
		cout << -1 << endl;
	else
		cout << ans << endl;

    return 0;
}

C++: /* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using graph = vector<vector<int>>;
using wgraph = vector<vector<pair<int, long long int>>>;
long long int INF = 1001001001001001LL;
int inf = 100100100;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

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

  for(int t = 0; t <= 10000000; t++) {
    if((60 * t + c) % (a + b) <= a) {
      cout << 60 * t + c << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}