solve :: Int -> [Int]
solve n = [x | x <- [1..n] , x `mod` 3 == 0 || elem '3' (show x)]

main :: IO ()
main  = readLn
    >>= return . solve
    >>= mapM_ (putStr . (" " ++) . show)
    >> putStrLn ""