program answer
  implicit none
  integer(8) :: i, K, a
  read(*,*) k

  a=7
  do i = 1, K
     if(mod(a,K)==0) then
        write(*,*) i
        stop
     end if
     a=mod(10*a+7,K)
  end do

  write(*,*) '-1'
  stop
 end program answer