import Control.Applicative

main = do
    n <- read <$> getLine
    putStrLn $
        concat $ zipWith (++) (repeat " ") (show <$> filterCheckNumber n)

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

includeThree :: Int -> Bool
includeThree x
    | x == 0          = False
    | x `mod` 10 == 3 = True
    | otherwise       = includeThree $ x `div` 10
