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

int dist[60];

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	
	memset(dist, -1, sizeof(dist));
	int t = 0;
	for (int k = 0; k < 3600; k++){
		for (int i = 0; i < a; i++){
			if (dist[t % 60] == -1) dist[t % 60] = t;
			t++;
			if (dist[t % 60] == -1) dist[t % 60] = t;
		}
		t += b;
	}
	
	printf("%d\n", dist[c]);
}