import Control.Applicative

includeThree :: Integer -> Bool
includeThree 0 = False
includeThree x
    | mod x 3 == 0 = True
    | otherwise    = includeThree $ div x 10

main :: IO()
main = do
    n <- read <$> getLine
    putStrLn (" " ++ (unwords . map show) [x | x <- [1 .. n], or [mod x 3 == 0, includeThree x]])