import qualified Data.Set as S
main = do
  k <- readLn :: IO Int
  print $ f k 7 S.empty

f :: Int -> Int -> (S.Set Int) -> Int
f k a s | m == 0 = 1 + S.size s
        | m `S.member` s = -1
        | otherwise = f k (m*10+7) $ S.insert m s
  where
    m = a `mod` k

