main = do
  s <- getLine
  let n = (read :: String -> Int) s
  putStrLn $ (concat $ map aux [1..n])

aux :: Int -> String
aux n
  | n `mod` 3==0 = " " ++ (show n)
  | elem '3' (show n) = " " ++ (show n)
  | otherwise = ""                      