#include <bits/stdc++.h>
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    for(int i=0;i<10000000;i++){
        if(c%(a+b)<=a){
            cout<<c<<endl;
            return 0;
        }
        c+=60;
    }
    cout<<-1<<endl;
}