module Main where
import Debug.Trace
import Data.List
import Data.Maybe
import Data.Ord
import Control.Monad

solve :: Int -> String
solve n = iter 1 where
    iter i
        | n < i = [] 
        | mod i  3 == 0 || mod i 10 == 3 = ' ': show i ++ iter (succ i)
        | i >= 10 = iter2 (div i 10)
        | otherwise = iter (succ i) where
            iter2 j
                | mod j 10 == 3 = ' ': show i ++ iter (succ i)
                | otherwise = iter (succ i)

readLine:: IO [Int]
readLine = fmap (map read . words) getLine

main :: IO() 
main = do
    [n] <- readLine
    putStrLn (solve n)

