main = putStrLn . unwords . map show . solve . read =<< getLine

checknum :: Int -> Bool
checknum x = x `rem` 3 ==0

include3 :: Int -> Bool
include3 x
  | x > 0 = x `rem ` 10 ==3 || include3 ( x `div` 10)
  | otherwise = False

solve :: Int -> [Int]
solve n = filter (\x -> checknum x|| include3 x) [1..n]