A, B = map(int, input().split()) if A % B == 0 or B % A == 0: print("-1") else: print((A - 1)*(B - 1))