#include "bits/stdc++.h"

using namespace std;

static void solve()
{
  int a, b, c;
  set<int> s;
  cin >> a >> b >> c;
  int now = 0;
  int d = 0;
  while (true) {
    if(now <= c && c <= now + a) {
      cout << d * 60 + c << "\n";
      return;
    }
    if(s.count(now)) {
      cout << -1 << "\n";
      return;
    }
    s.insert(now);
    now += a + b;
    d += now / 60;
    now %= 60;
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie();
  solve();
}