#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int a,b,c;



int main(){
    cin >> a>>b>>c;
    int round = a+b;
    int cnt=0;
    while(1){
        if((60*cnt+60)%(a+b)==0){
            if(c%(a+b)<=a)break;
            cnt = -1;
            break;   
        }
        if(c%(a+b)<=a)break;
        c+=60;
        cnt++;
    }
    if(cnt==-1){
        cout << cnt << endl;
    }else{
        cout << c << endl;
    }


}
