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

  if(k==1) then
     write(*,*) '1'
     stop
  else if(mod(k,2)==0) then
     write(*,*) '-1'
     stop
  end if

  do i = 1, 16
     a=(10**i-1)/9
     if(mod(7*a,K)==0) then
        write(*,*) i
        stop
     end if
  end do

if(mod(K,7)==0) then
     write(*,*) k-1
     stop
  end if

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