from math import gcd from heapq import * a, b, c = map(int, input().split()) if gcd(a, gcd(b, c)) != 1: print("INF") exit() a, b, c = sorted([a, b, c]) inf = 1 << 30 dist = [inf] * a dist[0] = 0 hq = [(0, 0)] while hq: d, pos = heappop(hq) if dist[pos] < d: continue i = d * a + pos for x in [b, c]: ni = i + x nd = ni // a npos = ni - a * nd if dist[npos] > nd: dist[npos] = nd heappush(hq, (nd, npos)) print(sum(dist))