a,b=map(int,input().split()) if a==2*b or b==2*a: print(3*min(a,b)) exit() elif a==3*b or b==3*a: print(2*min(a,b)) exit() elif double(a/b==1.5) or double(b/a==1.5): print(min(a,b)//2) print(-1)