a,b = map(int,input().split()) for c in range(1,a+b+1): if a != c and c != b: if (a+b)%c==0 and (b+c)%a==0 and (c+a)%b==0: print(c) exit() print(-1)