#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b, c, res = -1;
    cin >> a >> b >> c;
    for (int i=0; i<=a+b; ++i) {
        if ((c+i*60) % (a+b) <= a) {
            res = c+i*60;
            break;
        }
    }
    cout << res << endl;
}
