#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
  
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int ans = -1;
    for(int t = 0; t < 1000; t++){
        if((60 * t + c) % (a + b) <= a){
            ans = 60 * t + c;
            break;
        }
    }
    cout << ans << endl;
}