main = do
    n <- getInt
    mapM printThree [1..n]   
    putStrLn ""

printThree :: Int -> IO ()
printThree n 
    | isThree n = putStr $ " " ++ (show n)
    | otherwise = return ()

isThree :: Int -> Bool
isThree n 
    | n `mod` 3  == 0 = True
    | hasThree n      = True
    | otherwise       = False

hasThree :: Int -> Bool
hasThree n = any (\c -> c == '3') (show n)
--hasThree 0 = False
--hasThree 3 = True
--hasThree n = hasThree $ n `div` 10
    
getInt :: IO (Int)
getInt = do
    str <- getLine
    return $ read str
