module Main where

import Control.Applicative
import Numeric

main :: IO ()
main = do
  { [n] <- getInts
  ; call n
  }

call :: Int -> IO ()
call n = check_num n 1 1 

check_num :: Int -> Int -> Int -> IO ()
check_num n i x = if x `mod` 3 == 0
  then putStr (' ':show i) >> end_check_num n (succ i) x
  else include3 n i x
  
include3 :: Int -> Int -> Int -> IO ()
include3 n i x = if x `mod` 10 == 3
  then putStr (' ':show i) >> end_check_num n (succ i) x
  else if not (x' == 0) then include3 n i x'
       else end_check_num n (succ i) x'
  where
    x' = x `div` 10

end_check_num :: Int -> Int -> Int -> IO ()
end_check_num n i x = if i <= n then check_num n i i
  else putStrLn ""

--

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

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""

done :: IO ()
done = return ()

