#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define REP(i, n) for ( int i = 0; i < (n); i++ )
 
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);

  int a, b, c;
  cin >> a >> b >> c;

  int now = 0, sum = 0;
  for ( int i = 0; i < 100; i++ ) {
    if ( now <= c && c <= now+a ) {
      for ( int j = 0; j < 60; j++ ) {
	if ( now+j == c ) {
	  cout << sum+j << endl;
	  return 0;
	}
      }
    }
    sum += a+b;
    now += a+b;
    now %= 60;
  }

  cout << -1 << endl;

  return 0;
}

