import Control.Applicative

import Control.Monad
    (when)

type Problem = Int

type Result = [Int]

solve :: Problem -> Result

solve n
    = [x | x <- [1..n], (mod x 3 == 0) || (elem '3' $ show x)]

input :: IO Problem

input
    = do
        [n] <- map read.words <$> getLine
        return n

output :: Result -> IO ()

output xs
    = putStrLn $ concat [" " ++ show x | x <- xs]
    
main :: IO ()

main = output =<< solve <$> input