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() print(-1)