import Control.Applicative

makeLine n = filter (\x -> ((x `mod` 3 == 0) || (elem '3' . show $ x))) [1..n]

main :: IO ()
main = do
    putStr " "
    putStrLn =<< unwords . map show . makeLine <$> readLn
