#include <iostream>

using namespace std;

int main()
{
	int a, b, c, t = 0, Ans;

	cin >> a >> b >> c;

	while (t < 60)
	{
		int time = t * 60 + c;

		if (time % (a + b) >= 0 && time % (a + b) <= a)
		{
			Ans = t * 60 + c;

			break;
		}

		t++;

		if (t == 60) { Ans = -1; }
	}

	cout << Ans << endl;

	return 0;
}