import Control.Applicative

solver' :: Int -> Int -> [Int]
solver' i n
  | i <= n    =
    if (i `mod` 3 == 0) || (i `mod` 10 == 3)
      then i : solver' (i + 1) n
    else solver' (i + 1) n
  | otherwise = []

solver :: Int -> String
solver n = " " ++ unwords (map show (solver' 1 n))

main :: IO()
main = do
  n <- (read :: String -> Int) <$> getLine
  putStrLn $ solver n