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

int main(){

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

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

}