import           Control.Applicative
import           Control.Monad

check :: Int -> Bool
check n
    | n `mod` 3  == 0 = True
    | n `mod` 10 == 3 = True
    | otherwise       = div10 n

div10 :: Int -> Bool
div10 n
    | q <= 0    = False
    | q == 3    = True
    | otherwise = div10 q
  where
    q = n `div` 10

main :: IO ()
main = do
    n <- readLn :: IO Int
    let xs = fmap show $ filter check [1..n]
    let ys = foldr1 (\x acc -> x ++ " " ++ acc) xs
    putStrLn $ ' ' : ys

