main = do
  line <- getLine
  let 
    n = read $ head $ words line :: Int
    call i
      | i > n           = []
      | (mod i 3) == 0  = i : call (i+1)
      | otherwise       = include_3 i i
    include_3 x i 
      | x == 0          = call (i+1)
      | (mod x 10) == 3 = i : call (i+1)
      | otherwise       = include_3 (div x 10) i
    in putStrLn $ unwords $ map show $ call 1

