include3 :: Int -> Bool
include3 0 = False
include3 n
  | n `mod` 10 == 3 = True
  | otherwise = include3 $ n `div` 10

main :: IO ()
main = do
  n <- readLn
  putStrLn $ " " ++ unwords [show i | i <- [1..n], i `mod` 3 == 0 || include3 i]