import Data.Functor( (<$>))

main = do
    n <- read <$> getLine
    let
	almostAnswer = filter predicate [1..n]
	  where
	    predicate i
	      = let
		    str = show i
		    p1 = '3' `elem` str
		    p2 = i `mod` 3 == 0
		in
		    p1 || p2

    (\i -> putStr $ " "++(show i)) `mapM_` almostAnswer
    putStrLn ""

