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

int main()
{
	int a,b,c;
	int ans=-1;
	cin >> a >> b >> c;
	while(c<10000){
		if(c%(a+b)<=a){
			ans=c;
			break;
		}
		c+=60;
	}
	cout << ans << endl;
	return 0;
}

