#include <iostream>
using namespace std;

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

  if (a + b == 60) {
    if (c <= a)
      cout << c << endl;
    else
      cout << -1 << endl;
  } else {
    int t = a + b;
    if (c % t <= a)
      cout << c << endl;
    else {
      for (; ;) {
	c += 60;
	if (c < 0) {
	  cout << -1 << endl;
	  break;
	}
	if (c % t <= a) {
	  cout << c << endl;
	  break;
	}
      }
    }
  }
  return 0;
}