main = do
    s <- getLine
    let n = read s :: Int
    let ans = filter (\x -> checkNum x || include3 x) [1..n]
    putStrLn $ (" " ++ ) $ unwords $ map show ans

checkNum x = x `mod` 3 == 0

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