#include <iostream>
#include <cstdio>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int a,b,c;
    while(cin >> a >> b >> c){
        int ans = -1;
        rep(i,(a+b)*60){
            if(i%60==c){
                if(i%(a+b) <= a){
                    ans = i;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}