filter1 :: Int -> Bool
filter1 n = n `mod` 3 == 0

filter2 :: Int -> Bool
filter2 n
  | n < 3           = False
  | n `mod` 10 == 3 = True
  | otherwise       = filter2 (n `div` 10)

callFilter :: Int -> Bool
callFilter n = filter1 n || filter2 n

call :: Int -> [Int]
call n = filter callFilter [1..n]

main :: IO ()
main = do
    n <- getLine >>= \l -> return (read l :: Int)
    mapM_ putStr $ map (\n -> " " ++ show n) $ call n
    putStrLn ""
