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;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = 0; i < 100000; ++i) {
        int t = i * 60 + c;
        if (t % (a + b) <= a) {
            cout << t << "\n";
            return 0;
        }
    }
    cout << -1 << "\n";
    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;

int main(){

	  int a,b,c ;
	  cin >> a >> b >> c;


	  int x=c;
	  int t=0;
	  set<int> s;
	  while( c % (a+b) > a ) {
			c = c%(a+b);
			c += 60; t++;
			if( s.count(c) != 0){
				  cout << -1 << endl; return 0;
			}
			s.insert(c);
	  }
	  cout << x+(60*t) << endl;
	  return 0;

}

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

using namespace std;

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

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

int dist[60];

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	
	memset(dist, -1, sizeof(dist));
	int t = 0;
	for (int k = 0; k < 3600; k++){
		for (int i = 0; i < a; i++){
			if (dist[t % 60] == -1) dist[t % 60] = t;
			t++;
			if (dist[t % 60] == -1) dist[t % 60] = t;
		}
		t += b;
	}
	
	printf("%d\n", dist[c]);
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>
#include<set>
#include<stdio.h>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i);

using namespace std;


int main(){
	int a, b, c;
	cin >> a >> b >> c;
	
	bool flag = true;

	int time = 0, cnt = 0;
	rep(i,100){
		if(time <= c && c <= time + a){
			cout << 60*cnt + c << endl;
			flag = false;
			break;
		}
		time += a + b;
		if(time > 60){
			cnt++, time -= 60;
		}
	}
	if(flag)cout << -1 << endl;

	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	int a,b,c;
	int t,i;
	cin >> a >> b >> c;
	t=c;
	i=0;
	while(i<60){
		if((c+60*i)%(a+b)<=a){
			cout << (i*60+c) << '\n';
			break;
		}
		i++;
	}
	if(i==60){
		cout <<-1<< '\n';
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(60%(a+b)==0&&c%(a+b)>a)cout<<-1<<endl;
  else{
    int t=0;
    while(1){
      if((60*t+c)%(a+b)<=a){
        cout<<60*t+c<<endl;
        break;
      }
      t++;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
using namespace std;

#define ll long long int
#define ld long long double
#define reps(i,f,n) for(int i=f;i<n;i++)
#define rep(i,n) reps(i,0,n)
#define m1 cout<<"move1"<<endl
#define m2 cout<<"move2"<<endl
#define m3 cout<<"move3"<<endl
#define m4 cout<<"move4"<<endl

int main(){
  int flag = 1;
  int a,b,c;
  int t=0;
  int c_ans;

  cin>>a>>b>>c;
  c_ans = c;

  while(1){
    if( c+60*t - a <= 0 && flag == 1){
      //m1;
      cout<< c_ans + 60*t<<endl;
      break;
    }
    //else if(c + 60 * t - a <=0 && flag == 1){
    //t++;
    //flag = 0;
    //}
    else if(c + 60 * t - a >= 0 && flag == 1){
      //m2;
      c-=a;
      flag = 0;
    }
    else if(c + 60 * t - b == 0 && flag == 0){
      //m3;
      cout<<c_ans + 60 * t <<endl;
      break;
    }
    else if(c + 60 * t - b < 0 && flag == 0){
      if( 60 % ( a + b ) == 0){
	cout<<-1<<endl;
	break;
      }
      else{
	t++;
      flag = 1;
      c-=b;
      // m4;
      }
    }
    else {
      c -= b;
      flag = 1;
    }
  }

  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;
    for(int j=0;j<10000;j++){
      if(start<=c+60*j&&c+60*j<=end){
        cout<<c+60*j<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<endl;
	return 0;
}