import Control.Applicative
import Control.Monad

isThree :: Int -> Bool
isThree a 
    | a `mod` 3 == 0 = True
    | '3' `elem` (show a) = True
    | otherwise = False

main = do 
    num <- getLine
    putStr " "
    putStrLn $ unwords . (map show) $ filter isThree [1..(read num)]
