program main
    implicit none
    integer X, Y, i
    integer(8) N

    read(*,*) X, Y

    do i = 1, 1000000000
        N = X*i
        if(mod(N,Y)/=0)then
            write(*,*) N
            stop
        endif
    enddo

    write(*,*) -1


end program