-- Structured Program I - Structured Programming

main :: IO ()
main = do
  n <- readLn
  putStrLn $ " " ++ (unwords $ map show $ filter check [1..n])

check :: Int -> Bool
check x = (mod x 3 == 0) || (include3 $ show x)
  where
    include3 [] = False
    include3 (c : cs)
      | c == '3'  = True
      | otherwise = include3 cs

