#include <iostream>
using namespace std;

int main() {
  int a, b, c; cin >> a >> b >> c;
  int res = -1;
  for (int iter = 0; iter < 100; ++iter) {
	int q = c % (a + b);
	if (q <= a) {
	  res = c; break;
	}
	c += 60;
  }
  cout << res << endl;
}

