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 " " >> putStr (show i) >> end_check_num n i x
  else include3 n i x

include3 :: Int -> Int -> Int -> IO ()
include3 n i x = if x `mod` 10 == 3
  then putStr " " >> putStr (show i) >> end_check_num n i x
  else let x' = x `div` 10
           in if x' /= 0 then include3 n i x'
              else end_check_num n i x'

end_check_num :: Int -> Int -> Int-> IO ()
end_check_num n i x = let i' = i +1
                      in 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 ""

