a, b = map(int, input().split()) L = [] import math g = math.gcd(a, b) if g != 1: print(-1) exit() l = (a*b)//g for x in range(b+1): for y in range(a+1): z = a*x+b*y if z <= l: L.append(z) L = set(L) print(l-len(L)+1)