import math A,B = map(int, input().split()) print(-1 if math.gcd(A, B) > 1 else (A-1)*(B-1)//2)