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