import Text.Printf

func :: Int -> Int -> Int -> Int
func k' k total = func' total
  where
  func' t
    | t == 0 = 0
    | otherwise = q + func' p
      where
      x = k * k * k * (11 - t `mod` 10) `mod` 10
      (p, q) = quotRem (t + k' * x) 10

main :: IO ()
main = do
  kk <- fmap read getLine
  let k' = if kk `mod` 7 == 0 then kk `div` 7 else kk
      k = k' `mod` 10
      t = (k * k * k `mod` 10) * k' `div` 10
  printf "%d\n" $ if k `mod` 2 == 0 || k == 5 then -1 else 1 + func k' k t
