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