#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    int ts,te,cnt=0,ans;
    while(1){
        ts=(a+b)*cnt;
        te=a*(cnt+1)+b*cnt;
        if(ts%60<=c&&c-ts%60<=a){
            ans=60*(ts/60)+c;
            break;
        }
        if(ts!=0&&ts%60==0){
            ans=-1;
            break;
        }
        cnt++;
    }
    cout<<ans<<endl;
}