import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from fractions import gcd A,B = map(int,read().split()) g = gcd(A,B) a = A//g b = B//g c = 6 - a - b if sorted((a,b,c)) == [1,2,3]: print(c * g) else: print(-1)