module Main where

import Data.Functor

main :: IO ()
main =  do
 { [n] <- getInts
 ; putStrLn $ (' ':) $ unwords $ map show $ takeWhile (n >=) $ [ x | x <- [3 ..], mod x 3 == 0 || mod x 10 == 3 ]
 }

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