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;
  cin >> a >> b >> c;
  if( a + b == 60 ) cout << -1 << endl;
  else if( c <= a ) cout << c << endl;
  else if ( c > a ){
    if ( a + b < c ){
      cout << c << endl;
    }else if ( a + b > c ){
      int time = 0;
      int cnt = 0;
      while(1){
	time += a + b;
	cnt++;
	if( cnt == 100 ) break;
	if( time > 60 ){
	  int tmp = time -60;
	  int temp = c - tmp;
	  //  cout << "temp" << " " << temp << " " << "c" << " " << c << " " << "time" << " " << time << endl;
	  time += temp;
	  
	    cout << time << endl;
	    break;
	}
      }
    }
  }
  return 0;
}

C++: /*
2017_03_14_AC
????????????
????????§???????????§??°???????????°?????????????????§??????????????°??§AC??????????????£????????????

*/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

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

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

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    long long int count=0;
    long long int now=0;
    long long int ans=0;
    while (1) {
        if (count==10000000) {
            cout<<-1<<endl;
            break;
        } else {
            if (now<c&&now+a>=c) {
                cout<<ans+c-now<<endl;
                break;
            } else {
                now+=a+b;
                ans+=a+b;
                if (now>=60) {
                    now-=60;
                }
                count++;
            }
        }
    }
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    set<int> s;
    int current = 0;
    int ans = 0;
    while(true) {
        if(s.count(current) == 1) {
            ans = -1;
            break;
        }
        s.insert(current);
        bool finished=false;
        for(int i=1; i<=a; ++i) {
            if((current+i)%60 == c) {
                ans += i;
                finished = true;
                break;
            }
        }
        if(finished) {
            break;
        } else {
            current = (current + a + b)%60;
            ans += a + b;
        }
    }
    cout << ans << endl;
}

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int st, et;
  for(st = 0, et = a;; c += 60, st = et + b, et = st + a){
    if(c >= st && c <= et){
      cout << c << endl;
      break;
    }
    if(a + b == 60){
      cout << "-1" << endl;
      break;
    }
  }
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

#define int long long


signed main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int now = 0;
    while(now <= 3601) {
        for(int i=0; i<=a; ++i) {
            if(now > c) c += 60;
            if(now == c) {
                cout << now << endl;
                return 0;
            }
            now++;
        }
        for(int i=0; i<b-1; ++i) {
            now++;
            if(now > c) c += 60;
        }
    }
    cout << -1 << endl;
    return 0;
}

C++: int n,m,c,i;
main(){scanf("%d%d%d",&n,&m,&c);for(i=0;i<99;i++){if(c%(n+m)<=n)goto a;c+=60;}c=-1;a:printf("%d\n",c);}