#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007LL;
const double INF=1000000000;
const int MAX=100001;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    bool f=true;
    for(int i=c;i<=3600+c;i+=60){
        if(i%(a+b)<=a){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

                           

