main :: IO()
main = do
  n <- readLn
  mapM_ (\x -> putOrNothing x)[1..n]
  putStrLn ""

putOrNothing :: Int -> IO ()
putOrNothing n
    | n `mod` 3  == 0 || n `mod` 10 == 3 = putStr $  " " ++ show n
    | otherwise = return ()