def find_c(a,b,c): if (a+b) % c == 0 and (b+c) % a == 0 and (c+a) % b == 0: return True else: return False A,B = map(int,input().split()) C = -1 for i in range(1,A*B+1): if i == A or i == B: continue else: if find_c(A,B,i) == True: C = i break print(C)