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

  if(mod(7,K)==0) then
     write(*,*) '1'
     stop
  else if(mod(77,K)==0) then
     write(*,*) '2'
     stop
  else if(mod(777,K)==0) then
     write(*,*) '3'
     stop
   else if(mod(7777,K)==0) then
     write(*,*) '4'
     stop
   else if(mod(77777,K)==0) then
     write(*,*) '5'
     stop
   else if(mod(777777,K)==0) then
     write(*,*) '6'
     stop
  else
     write(*,*) '-1'
  end if

  stop
 end program answer
  