main :: IO()
main = do
  n <- readLn
  checkNum n 1
  putStrLn ""

checkNum :: Int -> Int -> IO ()
checkNum n i
    | n < i = return ()
    | i `mod` 3  == 0
        = do putStr $  " " ++ show i
             checkNum n (i+1)
    | otherwise
        = do include3 n i i

include3 :: Int -> Int -> Int -> IO ()
include3 n i x
    | x == 0
      = do checkNum n (i+1)
    | x `mod` 10 == 3
      = do putStr $  " " ++ show i
           checkNum n (i+1)
    | otherwise
        = include3 n i (x `div` 10)