import           Data.Functor

main :: IO ()
main = solve =<< readLn

solve :: Int -> IO ()
solve n = putStrLn
  $ (++) " "
  $ unwords
  $ show <$> filter predicate [1..n]
  where
    predicate x = divBy3 x || hasDigit3 x
    divBy3 x = x `mod` 3 == 0
    hasDigit3 x =
      let (d,r) = x `divMod` 10 in
      if d > 0
      then hasDigit3 d || r == 3
      else r == 3

