main :: IO ()
main = do
    n <- getLine
    putStrLn $ ' ':(ints2string $ call (read n :: Int))

ints2string :: [Int] -> String
ints2string = unwords.map show

call :: Int -> [Int]
call n = [x | x <- [1..n], check x]

check :: Int -> Bool
check n = checkMod3 n || checkMod10 n

checkMod3 :: Int -> Bool
checkMod3 n = n `mod` 3 == 0

checkMod10 :: Int -> Bool
checkMod10 0 = False
checkMod10 n = n `mod` 10 == 3 || checkMod10 (n `div` 10)