#include<bits/stdc++.h>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
 
using namespace std;
 
int a,b,c;
bool used[100];
 
int main(){
  cin >> a >> b >> c;
  int answer = 0, cur = 0;
  bool found = false;
  while( true ){
    if( used[cur%60] ) break;
    used[cur%60] = true;
    if( cur%60 <= c && c <= cur%60+a ) {
      found = true;
      answer = cur + c - cur % 60;
      break;
    }
    cur += a + b;
  }
 
  if( !found ) cout << -1 << endl;
  else cout << answer << endl;
 
  return 0;
}