from math import gcd a, b = map(int, input().split()) g = gcd(a, b) a //= g b //= g c = 6 - a - b if c > 0 and c != a and c != b: print(g * c) else: print(-1)