a,b=map(int, input().split()) D=[0]*(a*b) for i in range(a+1): for j in range(b+1): if b*i+a*j<=a*b: D[(b*i+a*j)-1]=1 d=D.count(0) import math z=math.gcd(a,b) if z==1: print(d) else: print(-1)