program proA
  implicit none
  integer*8 x,y,i,n
  
  read(*,*) x,y

  if(x==y.or.mod(x,y)==0) then
     write(*,*)-1
     stop
  end if
  i=1
  do while (x*i<1.0E+18)
     n=x*i
     if(mod(n,y) .ne. 0) then
        write(*,*) n
        stop
     end if
     i=i+1
  end do

  write(*,*) -1
end program proA
