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