#include <iostream>
using namespace std;

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	int x=c;
	int t=0;
	while(t<61){
		x=x-a;
		if(x<=0){
			cout<<(c+60*t)<<endl;
			return 0;
		}
		if(x<b){
			x=x+60-b;
			if(x==c){
				x=-1;
				cout<<x<<endl;
				return 0;
			}
			t++;
			continue;
		}else if (x==b){
			cout<<(c+60*t)<<endl;
			return 0;
		}else{
			x=x-b;
			if(x==c){
				x=-1;
				cout<<x<<endl;
				return 0;
			}
			continue;
		}
	}
	return 0;
}