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