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 n,m,b,c,d;
    bool a=false;
    cin>>n>>m>>b;c=b;
    for(int i=0;i<500000000;i++){
        if(c%(n+m)<=n && a==false){
            a=true;
            d=i;
        }
        c+=60;
    }
    if(a==false){
        cout<<"-1"<<endl;
    }
    else{
        c=b+d*60;
        cout<<c<<endl;
    }
    return 0;
}

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

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

    int t = 0;
    int T = a + b;   //??¨???

    while(t < 1000){
        
        int temp = (60*t + c) % T;
        if(0 <= temp && temp <= a){
            cout << 60*t + c << endl;
            return 0;
        }

        t++;
    }

    cout << -1 << endl;

    return 0;
}

C++: #include<iostream>

using namespace std;


int main(void){

  int a,b,c;
  int ans = -1;
  int t = 0;
  cin >> a >> b >> c;
  while(t< 10000){
    while(t > c) c+=60;
    if(t <= c && c <= t+a){
      ans = c;
      break;
    }
    t += a+b;
  }

  cout << ans << endl;

}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
	int a,b,c;
	cin >> a >> b >> c;
	int cur=0,ans=-1;
	rep(loop,4000){
		if(ans!=-1) break;
		int s=cur%60,t=(cur+a)%60;
		if(s<t&&s<=c&&c<=t) ans=cur+(c-s);
		if(t<s&&(s<=c||c<=t)) ans=cur+((s<=c)?(c-s):(60+c-s));
		cur+=a+b;
	}
	cout << ans << endl;
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<queue>	

using namespace std;

namespace MyLib {
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long
}
using namespace MyLib;

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

	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PI;
using namespace std;
#define MAX  999999
int main(){
    int a,b,c; cin >> a>>b>>c;
    int sum = a+b; ll ans = 0;
    for(int i = 0;10000;i++){
        ans=i*60+c;
        if(ans % (a+b)<=a){cout << ans << endl; break;}
        if(((a+b == 60) && c > a )|| i>5000){cout << -1 << endl; break;}
    }
     
}

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



int main(){

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


  int cnt = 0;

  int x1 = 1, x2 = a;


  if(60 % (a+b) == 0){
    int cp = c;
    while(1){
      if(cp < x1){
	cp += 60;
	cout << -1 << endl;
	break;
      }
      if(c >= x1 && c <= x2){
	
	cout << c << endl;
	break;
      }else{
	x1=x2+b;
	x2=x1+a;
      }
      
    }

  }else {
    int cp = c;
    while(1){

      if(cp < x1){
	cp += 60;
	//cout << cp << endl;
	cnt++;
      }    
      if(cp >= x1 && cp <= x2){
	cout << cp << endl;
	break;
      }else{
	x1=x2+b;
	x2=x1+a;
      }
      if(cnt >= 1000){
	cout << -1 << endl;
	break;
      }
    }
  }
  }


}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define REPR(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) \
  for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORR(i, a, b) \
  for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)
#define ALL(f, x, ...) \
  ([&](auto& y) { return (f)(begin(y), end(y), ##__VA_ARGS__); })(x)
auto INDEX = [](auto& x, auto& xs) { return &x - &xs[0]; };
void async_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
const auto inf = INT_MAX / 3;
const auto pi = 2 * std::acos(0.0);
const auto eps = 1e-14;
using ll = signed long long;
using ull = unsigned long long;

signed main() {
  async_io();
  int a, b, c;
  cin >> a >> b >> c;
  // [0..a] + [a+b % 60 .. $0 + a % 60] ...
  bool seeked[60];
  for (int i = 0, j = 0;;) {
    if (seeked[i]) {
      cout << "-1";
      return 0;
    }
    if (i <= c and c <= i + a) {
      cout << 60 * j + c << "";
      return 0;
    }
    seeked[i] = true;
    if (i + a + b >= 60) j++;
    i = (i + a + b) % 60;
  }
}