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>
 
#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 t = 0;
    int vis[60] = {};
    while (1) {
        int mt = t % 60;
        if (mt <= c && mt + a >= c) {
            cout << t - mt + c << endl;
            break;
        }
        if (vis[t]) {
            cout << -1 << endl;
            break;
        }
        vis[t] = 1;
        t += a + b;
    }
    return 0;
}

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

using namespace std;

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

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int mod=c%(a+b);
    if(mod<=a) printf("%d\n",c);
    else if(60%(a+b)==0) printf("-1\n");
    else {
        int ans=c;
        while(mod%(a+b)>a) mod=(mod+60)%(a+b),ans+=60;
        printf("%d\n",ans);
    }
}

C++: #include <iostream>
#include <vector>

using namespace std;


int a,b,c;

int main(){

	int flag = 0;
	int t=0;
	int i = 0;

	cin >> a >> b >> c;


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

		if(flag == 0){
			t += a;
			flag = 1;
		}
		else if(flag == 1){
			t += b;
			flag = 0;
			i++;

		}

		if(flag == 1){
			if(t >= c + 60 * i){
				cout << c + 60*i << endl;
				return 0;
			}
		}
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>

using namespace std;

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

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

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

int main(void){
    int awake, asleep, destination;
    cin >> awake >> asleep >> destination;

    int now = 0;
    int a = awake, b = 0;

    while(1){
        if( now > 60 && (awake+asleep)%60 == 0 ){
            cout << -1 << endl;
            return 0;
        }
        //if( now!=0 && now%60==0 && a==awake ){
        //    cout << -1 << endl;
        //    return 0;
        //}
        if( now%60==destination && (a!=0 || (a==0 && b==asleep))){
            cout << now << endl;
            return 0;
        }

        if(a){
            a--;
            now++;
            if(a == 0){
                b = asleep;
            }
        }else if(b){
            b--;
            now++;
            if(b == 0){
                a = asleep;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	int t = 0;
	REP(j, INF) {
		if (t % 60 == 0 && j != 0) {
			cout << -1 << endl;
			return 0;
		}
		REP(i, a) {

			if (t % 60 == c) {
				cout << t << endl;
				return 0;
			}
			t++;
		}
		if (t % 60 == c) {
			cout << t << endl;
			return 0;
		}
		t += b;

	}
	return 0;
}

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{
      now+=(a+b);
      t++;
    }
  }
  if(!ok)cout<<-1<<endl;
}

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