import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.Map as M
import Text.Printf

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
  n <- readLn
  putChar ' '
  putStrLn $ unwords $ map show $ solve n

solve :: Int -> [Int]
solve n = [ i | i <- [1..n], i `rem` 3 == 0 || i `has` 3 ]
  where
    x `has` k
      | r == k    = True
      | q == 0    = False
      | otherwise = q `has` k
      where (q, r) = x `quotRem` 10

