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

printThree :: Int -> IO ()
printThree n 
    | isThree n = print " " >> print n
    | otherwise = return

--printSpaceWith :: Show a => a -> IO ()
--printSpaceWith a = do
--    print " "
--    print a

isThree :: Int -> Boolean
isThree n 
    | n `mod` 3  == 0 = True
    | n `mod` 10 == 3 = True
    | otherwise       = False
    
getInt :: IO (Int)
getInt = do
    str <- getLine
    return $ read str
