#include <bits/stdc++.h>
using namespace std;

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    int now = 0;
    vector<int> visited(60, 0);

    while(1){
        int t = now % 60;
        if(visited[t]){
            cout << -1 << endl;
            return 0;
        }
        if(t <= c && c <= t + a){
            cout << now + c - t << endl;
            return 0;
        }

        visited[t] = 1;
        now = now + a + b;
    }

    return 0;
}