#include <iostream>
using namespace std;

int GCD(int m, int n)
{
	if (n == 0)return m;
	return GCD(n, m % n);
}

int main()
{
	int a, b, c, lcm, n, res = -1;
	cin >> a >> b >> c;
	lcm = 60*(a+b)/GCD(60,a+b);
	n = lcm*c/GCD(lcm,c);
	for (int i = 0; i < n; i++) {
		if ((c + 60 * i) % (a + b) >= 0 && (c + 60 * i) % (a + b) <= a) {
			res = c + 60 * i;
			break;
		}
	}
	cout << res << endl;
	return 0;
}