import Control.Monad

find n i = do
  if i > 0 then
      if i `mod` 10 == 3 then putStr $ " " ++ show n else find n (i `div` 10)
  else
      return ()

call n i = do
  if i <= n then do
    if i `mod` 3 == 0 then putStr $ " " ++ show i else find i i
    call n (i+1)
  else return ()

main = do
  s <- getLine
  let n = read s::Int
  call n 1
  putStrLn ""