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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  bool flag = true;
  int time = 0, cnt = 0;
  for(int i = 0; i < 100; i++){
    if(time <= c && c <= time + a){
      cout << 60*cnt + c << endl;
      flag = false;
      break;
    }
    time += a + b;
    if(time > 60){
      cnt++, time -= 60;
    }
  }
  if(flag)cout << -1 << endl;
}