#include <iostream>
using namespace	std;

int main() {
  int a, b, c;
  cin >> a >> b	>> c;
  int sum = 0;

  for(int i = 0;; i++) {
    if(sum%60 <= c && c <= (sum%60+a)) {
      cout << sum/60*60 + c << endl;
      break;
    }
    sum	+= a + b;
    if(sum % 60 == 0) {
      cout << "-1" << endl;
      break;
    }
  }

  return 0;
}

