#include <iostream>
#include <algorithm>
using namespace std;

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