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

int main(){
  int a,b,c,p=0,sum=0;
  bool visited[60]={};
  cin>>a>>b>>c;
  while(1){
    if(visited[p]){
      cout<<-1<<endl;
      break;
    }
    visited[p]=true;
    if(p<=c&&c<=p+a){
      cout<<sum+c-p<<endl;
      break;
    }
    p=(p+a+b)%60;
    sum=sum+a+b; 
  }
  return 0;
}