#include <bits/stdc++.h>

using namespace std;

bool isin(int a,int c,int b){
	//c is in [a-b]
	return ((a < b) && (a <= c && c <= b)) || ((b < a)&&(a <= c||c <= b));
}

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