#include<iostream>
using namespace std;

int a, b, c;

int main() {
	cin >> a >> b >> c;
	int i, j, t = 0;
	for( i = 0; i < 100; i++) {
		for( j = 0; j <= a; j++) {
			if (t % 60 == c)
				break;
			t += (j < a);
		}
		if ( j <= a )
			break;
		t += b;
	}
	if ( i < 100 )
		cout << t << endl;
	else
		cout << -1 << endl;
	return 0;
}