import Control.Applicative
import Data.List

isAnyDigitThree :: Int -> Bool
isAnyDigitThree 0 = False
isAnyDigitThree n = (if n`mod`10==3 then True else isAnyDigitThree (n`div`10))

threeList :: Int -> [Int]
threeList n = [ x | x<-[1..n], (x`mod`3==0) || isAnyDigitThree x ]

main = getLine >>= putStrLn . (" "++) . unwords . (map show) . threeList . (read::String->Int)