import Control.Applicative
import Control.Monad

rInt s = read s :: Int

checkNum x = mod x 3 == 0
include3 x 
	| x==0 = False
	| mod x 10 == 3 = True
	| otherwise = include3 $ div x 10

main  = do
	n <- readLn
	putStrLn $ unwords $ "" : (map show $ filter f [1..n])
		where
			f x = or $ [include3, checkNum] <*> [x]