haveThree::Int->Bool
haveThree x = elem 3 $ map (`mod`10) $ takeWhile (>0) $map (x`div`) $ map ((^) 10) [1,2..]


main=do
n <- getLine
putStrLn $ (:) ' ' . unwords . map show $ takeWhile (<=(read n::Int)) $ filter (\x->x`mod`3==0||haveThree x) [1,2..]