import Control.Applicative
import Data.List
main = do
    n <- readLn
    putStrLn $ " " ++ intercalate " " [show x | x <- [1..(n :: Int)], mod x 3 == 0 || hasThreeIn x]

hasThreeIn :: Int -> Bool
hasThreeIn x = any (== '3') $ show x